cmakepp_lang/types/is_callable
Defines functions for checking if a function can be run with the specified signature. This is used, for example, to enforce strong typing on class member functions.
- cmakepp_lang/types/is_callable._cpp_compare_names(result lhs rhs)
Handles logic for comparing the human-readable names of the functions.
This function compares the name part of two signatures (i.e., the 0th element) in a case-insensitive manner.
- Parameters:
result (desc) – The name for the variable which will hold the result.
lhs – The signature of the first function.
rhs – The signature of the second function.
- Returns:
result
will be set toTRUE
if the two signatures have the same name (up to case-sensitivity) andFALSE
otherwise.- Return type:
bool
Note
This routine has been factored out to facilitate testing of is_callable. It is not meant for use outside of the scope of comparing function signatures.
- cmakepp_lang/types/is_callable._cpp_compare_lengths(result fxn args)
Attempts to rule out a signature match based on length arguments alone.
For non-variadic functions we know that if one signature is longer than the other they can’t possibly be a match. For a variadic function with \(n\) required positional arguments we know that if the user provided less than \(n\) arguments, this function can not possibly be called with the provided arguments.
- Parameters:
result (desc) – Name for variable which will hold the result.
fxn (list*) – The signature of the function we are trying to call.
args (list*) – The signature of how we are trying to call the function.
- Returns:
result
will be set toTRUE
if we can call the function with the provided arguments andFALSE
otherwise.- Return type:
bool
Note
This routine has been factored out to facilitate testing of is_callable. It is not meant for use outside of the scope of comparing function signatures.
- cmakepp_lang/types/is_callable.cpp_is_callable(result fxn args)
Determines if a function can be run as the specified signature.
This function takes two lists
fxn
andargs
. Each list is interpreted as being a function signature such that the first element is the name of the function and the remaining arguments are: the types of the arguments the function was declared to take (forfxn
) or the types of the arguments being passed in (forargs
). This function ultimately determines whether there is a series of implicit casts which will convert the types inargs
into those infxn
. If there is thanfxn
is callable as the signature provided byargs
. If there is no such set of casts thenfxn
is not callable with the signature provided byargs
.- Parameters:
result (desc) – Name of the variable which will hold the result.
fxn (list*) – The signature of the function we are trying to cast to.
args (list*) – The signature of the function we are trying to cast from.
- Returns:
result
will be set toTRUE
ifargs
can be cast tofxn
andFALSE
otherwise.- Return type:
bool
- Variables:
CMAKEPP_LANG_DEBUG_MODE (bool) – Used to determine if CMakePP is being run in debug mode.
Error Checking
If CMakePP is run in debug mode this function will ensure that only three arguments are provided and that each argument has the correct type. If any of these asserts fail an error will be raised. These assertions are only done in debug mode.