39 lines
1.1 KiB
Plaintext
39 lines
1.1 KiB
Plaintext
[#currying]
|
|
[section Currying]
|
|
|
|
A [link metafunction template metafunction] supports ['currying] when it accepts
|
|
less arguments than it normally expects. When less arguments are provided, then
|
|
it returns a [link metafunction_class 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 [link boxed_value boxed] `1` value.
|
|
|
|
[endsect]
|
|
|