contains_type.h File Reference
Go to the source code of this file.
Defines | |
#define | CONTAINS_TYPE_(NAME) |
the CONTAINS_TYPE_(NAME) macro generates a compile time testing class, that allows for checking whether a type is defined within a type/class like a configuration description. |
Define Documentation
#define CONTAINS_TYPE_ | ( | NAME | ) |
the CONTAINS_TYPE_(NAME) macro generates a compile time testing class, that allows for checking whether a type is defined within a type/class like a configuration description.
- Parameters:
-
[in] NAME is the name of the subtype, that has to be tested.
The checking is complete done at compile time, thus no resources are wasted. It works with overloading of functions that have different return types and signatures and using SFINAE. Dependend of the return type and using the sizeof-trick we are able to detect whether a type is specified as a subtype or not.
contains_type_NAME<T>::value returns 1 if NAME exicist within T as defined subtype and 0 else.
How to use it? Here is an example:
struct TypeWithTestType { typedef int TestType; }; CONTAINS_TYPE_(TestType); contains_type_TestType<int>::value; // returns 0 contains_type_TestType<TypeWithTestType>:: value // returns 1