cmakepp_lang/algorithm/contains
- cmakepp_lang/algorithm/contains.cpp_contains(result item list)
Determines if an element appears in a set-like object.
This function is meant to function like Python’s
in
operation. Basically it encapsulates the process of checking ifx
is iny
. What “is in” means depends on the types ofx
andy
. For example ify
is a list, then “is in” checks to see ifx
is an item in that list. Alternatively ify
is a string then this function will check ifx
is a substring ofy
.- Parameters:
result (desc) – Name for the variable to hold the result.
item (str) – The item whose inclusion in
list
is in question.list (str) – The collection we are looking for
item
in.
- Returns:
result
will be set toTRUE
ifitem
is inlist
andFALSE
otherwise.- Return type:
bool
- Variables:
CMAKEPP_LANG_DEBUG_MODE (bool) – Used to determine if CMakePP is being run in debug mode or not.
Example Usage
The following snippet shows how to determine if the word
"hello"
is in the list"hello;world"
.include(cmakepp_lang/logic/contains) set(a_list "hello" "world") cpp_contains(result "hello" "${a_list}") message("The list contains 'hello': ${result}") # Will print TRUE
Error Checking
If CMakePP is run in debug mode this function will ensure that it is called with the correct number of arguments and that those arguments have the correct types. These error checks are only performed if CMakePP is run in debug mode.