A Metafunction is a class template that represents a function invocable at compile-time. A metafunction is invoked by instantiating the class template with particular template parameters (metafunction arguments); the result of metafunction application is accessible through the instantiation's nested type
typedef. A metafunction can have a variable number of parameters.
// binary metafunction template< typename T1, typename T2 > struct is_same { typedef false_c type; };template< typename T > struct is_same { typedef true_c type; };
// metafunction invocation typedef is_same<int,char>::type res; BOOST_STATIC_ASSERT(!res::value);
Expression | Expression type |
---|---|
typename f::type | A type |
typename f<t1,..,tn>::type | A type |
Expression | Complexity | Precondition | Semantics | Postcondition |
---|---|---|---|---|
typename f::type | Metafunction dependent | f is a nullary metafunction; f::type is a type-name | f::type is the result of the metafunction invocation | |
typename f<t1,..,tn>::type | Metafunction dependent | f is an n -ary metafunction; t1,..,tn are types; f<t1,..,tn>::type is a type-name | f<t1,..,tn>::type is the result of the metafunction invocation with the input arguments t1,..,tn |
plus
logical_not
size
max_element
Metafunctions, [Metafunction Class]