metafunction_class.qbk 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. [#metafunction_class]
  2. [section Template metafunction class]
  3. A ['template metafunction class] is a type with a public nested
  4. [link metafunction template metafunction] called `apply`. Since it is a type, it can be
  5. passed to template metafunctions as arguments and metafunctions can return it as
  6. their result. This makes it possible to implement
  7. ['higher-order template metafunctions], which are template metafunctions taking
  8. template metafunctions as arguments or returning template metafunctions as their
  9. result.
  10. For example this is the identity template metafunction class:
  11. struct identity
  12. {
  13. template <class T>
  14. struct apply
  15. {
  16. using type = T;
  17. };
  18. using type = identity;
  19. };
  20. This metafunction class is called `identity`. It takes one argument, `T`. The
  21. result of calling this metafunction class is its argument, `T`. Note that the
  22. `identity` metafunction class is also a
  23. [link metaprogramming_value template metaprogramming value], so it can be an
  24. argument or the result of a template metafunction.
  25. To call this metafunction, one has to call the nested template metafunction.
  26. For example:
  27. identity::apply<std::integral_constant<int, 13>>::type
  28. The above example calls the metafunction class `identity` with
  29. `std::integral_constant<int, 13>` as its argument.
  30. [endsect]