A mechanism for selecting between either of two types based on a compile time constant expression. More...
#include <classTraits.h>
A mechanism for selecting between either of two types based on a compile time constant expression.
The EvalTypeIf<a,b,c> template allows you to select one of two type definitions (b or c) based on boolean value (a). To use it, you create some compile time expression that evaluates to true or false, and then use that expression to select either of the two type definitions:
For example:
typedef typename EvalTypeIf<0, firstPossibleType, secondPossibleType>::type MyType;
selects the firstPossibleType and
MyType::type is firstPossibleType.
If the first template parameter is 1, then
MyType::type is secondPossibleType
In practice, specializations define the possiblities, and a compile time constant expression selection among the choices. For example:
typedef EvalTypeIf< sizeof(int) > sizeof(char), char, int>::type ValueType; // // here, ValueType will be 'int' because sizeof(int) > sizeof(char) //
More often, instead of using explict constants (0 or 1) or even explict boolean expressions for the selector (argument 1), you will use one of the template classes that define compile time constants based on their arguments. For example, argument 1 to EvalTypeIf will most like be one of:
isSameType<A,B>::value
isConstType<A>::value
isConvertibleType<From,To>::value
isClassType<A>::value
isPointerType<A>::value
isPodType<A>::value
isPolymorphicType<A>::value
isSignedType<A>::value
isUnsignedType<A>::value // does not include floats or enums
isArithmeticType<A>::value
isEnumType<A>::value
isFloatType<A>::value
isIntegralType<A>::value
isEnumType<A>::value
isTemplate<A>::value
basicClassType<A>::value -- defines a unique integer identifier for basic kind type
in the C++ language. See enumeration @ref cxxtls::basicClassTypes, below.
Definition at line 96 of file classTraits.h.
1.6.3