Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Currying

A template metafunction supports currying when it accepts less arguments than it normally expects. When less arguments are provided, then it returns a template metafunction class expecting the remaining arguments. That template metafunction class is also expected to support currying.

For example assuming the following metafunction is given:

template <class A, class B>
struct plus;

It takes two values, adds them and returns their result. For example:

static_assert(
  plus<
    std::integral_constant<int, 11>,
    std::integral_constant<int, 2>
  >::type::value == 13,
  "This should work"
);

If it supports currying, then the following should also work:

using inc = plus<std::integral_constant<int, 1>>;

static_assert(
  inc::apply<std::integral_constant<int, 12>>::type::value == 13,
  "This should work"
);

The above example defines the inc template metafunction class by calling plus with just one argument: the boxed 1 value.


PrevUpHomeNext