metafunction.qbk 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. [#metafunction]
  2. [section Template metafunction]
  3. A ['template metafunction] represents a function over types that is evaluated at
  4. compile-time. It is implemented by a template class.
  5. The template arguments of that class are expected to be types (`class` or
  6. `typename` template arguments). They represent the arguments of the
  7. metafunction.
  8. Instances of the template class are expected to have a public nested type called
  9. `type`. This type is the type the metafunction returns.
  10. Template metafunction are expected to be called with
  11. [link metaprogramming_value template metaprogramming values] as arguments only.
  12. Template metafunctions are expected to return template metaprogramming values.
  13. For example this is the identity template metafunction:
  14. template <class T>
  15. struct identity
  16. {
  17. using type = T;
  18. };
  19. This metafunction is called `identity`. It takes one argument, `T`. The result
  20. of calling this metafunction is its argument, `T`.
  21. To call this metafunction, one has to instantiate the template class. The
  22. template arguments it is instantiated with are the arguments the metafunction is
  23. called with. For example:
  24. identity<std::integral_constant<int, 13>>::type
  25. The above example calls the metafunction `identity` with
  26. `std::integral_constant<int, 13>` as its argument.
  27. [endsect]