
Boost : 
From: Peter Dimov (pdimov_at_[hidden])
Date: 20200929 11:35:34
Fletcher, John P wrote:
> Hi
>
> I have been playing around with lambda2 to see what I can do.
>
> I have an example from
> http://www.enseignement.polytechnique.fr/informatique/INF478/docs/Cpp/en/cpp/algorithm/for_each.html
> where the task is to increment an array of integers:
>
> std::vector<int> nums{3, 4, 2, 9, 15, 267};
> std::for_each(nums.begin(), nums.end(), [](int &n){ n++; }); The nearest I
> can get with lambda2 is this:
>
> std::for_each( nums.begin(),nums.end(), (_1 + 1) );
>
> This compiles although I have found no way to store back the result.
With for_each, there are three possible ways to write it, none of which is
supported by Lambda2:
std::for_each( nums.begin(),nums.end(), _1 = _1 + 1 );
std::for_each( nums.begin(),nums.end(), _1 += 1 );
std::for_each( nums.begin(),nums.end(), ++_1 );
Of those, the first one is impossible because op= must be a member, and the
latter two are possible in principle, but fall outside the initial scope of
the library.
There's also
std::transform( nums.begin(),nums.end(), nums.begin(), _1 + 1 );
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk