Date: Tue, 14 Apr 2020 21:10:54 -0400
On Tue, Apr 14, 2020 at 8:41 PM Justin Bassett via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> I use the function objects in <functional> all the time in conjunction
> with algorithms. However, sometimes, I find that I really want a curried
> function. For example:
>
> find_if(b, e, not_equal_to(0));
> transform(b, e, plus(1));
> copy_if(b, e, o, less(0))
>
In C++14, you can say
auto plus1 = [](auto x) { return x + 1; };
std::transform(b, e, dest, plus1);
or even
auto plus = [](auto x) { return [x](auto y) { return x + y; }; };
std::transform(b, e, dest, plus(1));
if the parameter absolutely *must* be substituted in at run time.
Do these not fit your needs for production code? If not, why not?
–Arthur
std-proposals_at_[hidden]> wrote:
> I use the function objects in <functional> all the time in conjunction
> with algorithms. However, sometimes, I find that I really want a curried
> function. For example:
>
> find_if(b, e, not_equal_to(0));
> transform(b, e, plus(1));
> copy_if(b, e, o, less(0))
>
In C++14, you can say
auto plus1 = [](auto x) { return x + 1; };
std::transform(b, e, dest, plus1);
or even
auto plus = [](auto x) { return [x](auto y) { return x + y; }; };
std::transform(b, e, dest, plus(1));
if the parameter absolutely *must* be substituted in at run time.
Do these not fit your needs for production code? If not, why not?
–Arthur
Received on 2020-04-14 20:14:01