On Tue, Sep 29, 2020 at 6:36 AM Peter Dimov via Boost
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... 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,
It seems that this is possible, just outside the scope of the lib. You could provide your own placeholders, and overload op=, right? I don't consider std::for_each to be an essential use case; I'm just wondering if there's a technical limitation I'm missing. Zach