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
inoperation. Basically it encapsulates the process of checking ifxis iny. What “is in” means depends on the types ofxandy. For example ifyis a list, then “is in” checks to see ifxis an item in that list. Alternatively ifyis a string then this function will check ifxis a substring ofy.- Parameters:
result (desc) – Name for the variable to hold the result.
item (str) – The item whose inclusion in
listis in question.list (str) – The collection we are looking for
itemin.
- Returns:
resultwill be set toTRUEifitemis inlistandFALSEotherwise.- 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.