Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
Front Page / Metafunctions / Type Selection / eval_if

eval_if

Synopsis

template<
      typename C
    , typename F1
    , typename F2
    >
struct eval_if
{
    typedef unspecified type;
};

Description

Evaluates one of its two nullary-metafunction arguments, F1 or F2, depending on the value C.

Header

#include <boost/mpl/eval_if.hpp>

Parameters

Parameter Requirement Description
C Integral Constant An evaluation condition.
F1, F2 Nullary Metafunction Metafunctions to select for evaluation from.

Expression semantics

For any Integral Constant c and nullary Metafunctions f1, f2:

typedef eval_if<c,f1,f2>::type t;
Return type:Any type.
Semantics:If c::value == true, t is identical to f1::type; otherwise t is identical to f2::type.

Example

typedef eval_if< true_, identity<char>, identity<long> >::type t1;
typedef eval_if< false_, identity<char>, identity<long> >::type t2;

BOOST_MPL_ASSERT(( is_same<t1,char> ));
BOOST_MPL_ASSERT(( is_same<t2,long> ));

See also

Metafunctions, Integral Constant, eval_if_c, if_