123456789101112131415161718192021222324252627282930313233343536373839 |
- [#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]
|