metaparse/doc/metafunction_class.qbk
2015-10-20 12:22:15 +09:00

40 lines
1.3 KiB
Plaintext

[#metafunction_class]
[section Template metafunction class]
A ['template metafunction class] is a type with a public nested
[link metafunction template metafunction] called `apply`. Since it is a type, it can be
passed to template metafunctions as arguments and metafunctions can return it as
their result. This makes it possible to implement
['higher-order template metafunctions], which are template metafunctions taking
template metafunctions as arguments or returning template metafunctions as their
result.
For example this is the identity template metafunction class:
struct identity
{
template <class T>
struct apply
{
using type = T;
};
using type = identity;
};
This metafunction class is called `identity`. It takes one argument, `T`. The
result of calling this metafunction class is its argument, `T`. Note that the
`identity` metafunction class is also a
[link metaprogramming_value template metaprogramming value], so it can be an
argument or the result of a template metafunction.
To call this metafunction, one has to call the nested template metafunction.
For example:
identity::apply<std::integral_constant<int, 13>>::type
The above example calls the metafunction class `identity` with
`std::integral_constant<int, 13>` as its argument.
[endsect]