EvalTypeIf< bool, ZeroClass, OneClass > Struct Template Reference

A mechanism for selecting between either of two types based on a compile time constant expression. More...

#include <classTraits.h>

Detailed Description

template<bool, class ZeroClass, class OneClass>
struct cxxtls::EvalTypeIf< bool, ZeroClass, OneClass >

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:

       isUnsignedType<A>::value     // does not include floats or enums
       basicClassType<A>::value  -- defines a unique integer identifier for basic kind type
                                    in the C++ language.  See enumeration @ref cxxtls::basicClassTypes, below.
See also:
isPolymorphicType_selector template below for a realistic example use of EvalTypeIf
classTraits_documentation for more info on how this works.
If you you get compile errors because one or the other of the alternative types being selected won't compile, you can use the "_selector" strategy below instead of the EvalTypeIf strategy.
See also:

Definition at line 96 of file classTraits.h.

The documentation for this struct was generated from the following file:
Generated on Wed Feb 29 22:54:39 2012 for CXXUtilities by  doxygen 1.6.3