12345678910111213141516171819202122232425262728293031323334353637383940 |
- [#metafunction]
- [section Template metafunction]
- A ['template metafunction] represents a function over types that is evaluated at
- compile-time. It is implemented by a template class.
- The template arguments of that class are expected to be types (`class` or
- `typename` template arguments). They represent the arguments of the
- metafunction.
- Instances of the template class are expected to have a public nested type called
- `type`. This type is the type the metafunction returns.
- Template metafunction are expected to be called with
- [link metaprogramming_value template metaprogramming values] as arguments only.
- Template metafunctions are expected to return template metaprogramming values.
- For example this is the identity template metafunction:
- template <class T>
- struct identity
- {
- using type = T;
- };
- This metafunction is called `identity`. It takes one argument, `T`. The result
- of calling this metafunction is its argument, `T`.
- To call this metafunction, one has to instantiate the template class. The
- template arguments it is instantiated with are the arguments the metafunction is
- called with. For example:
- identity<std::integral_constant<int, 13>>::type
- The above example calls the metafunction `identity` with
- `std::integral_constant<int, 13>` as its argument.
- [endsect]
|