currying.qbk 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. [#currying]
  2. [section Currying]
  3. A [link metafunction template metafunction] supports ['currying] when it accepts
  4. less arguments than it normally expects. When less arguments are provided, then
  5. it returns a [link metafunction_class template metafunction class] expecting
  6. the remaining arguments. That template metafunction class is also expected to
  7. support currying.
  8. For example assuming the following metafunction is given:
  9. template <class A, class B>
  10. struct plus;
  11. It takes two values, adds them and returns their result. For example:
  12. static_assert(
  13. plus<
  14. std::integral_constant<int, 11>,
  15. std::integral_constant<int, 2>
  16. >::type::value == 13,
  17. "This should work"
  18. );
  19. If it supports currying, then the following should also work:
  20. using inc = plus<std::integral_constant<int, 1>>;
  21. static_assert(
  22. inc::apply<std::integral_constant<int, 12>>::type::value == 13,
  23. "This should work"
  24. );
  25. The above example defines the `inc` template metafunction class by calling
  26. `plus` with just one argument: the [link boxed_value boxed] `1` value.
  27. [endsect]