[Home]Metafunction

Description

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.

Example

// 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);

Valid expressions

 Expression  Expression type  
typename f::typeA type
typename f<t1,..,tn>::typeA type

Expression semantics

 Expression  Complexity  Precondition  Semantics  Postcondition 
typename f::typeMetafunction dependentf is a nullary metafunction; f::type is a type-namef::type is the result of the metafunction invocation
typename f<t1,..,tn>::typeMetafunction dependentf is an n-ary metafunction; t1,..,tn are types; f<t1,..,tn>::type is a type-namef<t1,..,tn>::type is the result of the metafunction invocation with the input arguments t1,..,tn

Models

See also

Metafunctions, [Metafunction Class]


Table of Content
Last edited July 16, 2002 11:27 pm