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 if x is in y. What “is in” means depends on the types of x and y. For example if y is a list, then “is in” checks to see if x is an item in that list. Alternatively if y is a string then this function will check if x is a substring of y.

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 to TRUE if item is in list and FALSE 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.