|
Boost : |
From: Fletcher, John P (j.p.fletcher_at_[hidden])
Date: 2020-09-28 21:08:34
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<http://www.enseignement.polytechnique.fr/informatique/INF478/docs/Cpp/en/cpp/container/vector.html><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.
John Fletcher
std::for_each - cppreference.com - polytechnique<http://www.enseignement.polytechnique.fr/informatique/INF478/docs/Cpp/en/cpp/algorithm/for_each.html>
Applies the given function object f to the result of dereferencing every iterator in the range [first, last), in order.. If InputIt is a mutable iterator, f may modify the elements of the range through the dereferenced iterator. If f returns a result, the result is ignored.
www.enseignement.polytechnique.fr
________________________________
From: Boost <boost-bounces_at_[hidden]> on behalf of Peter Dimov via Boost <boost_at_[hidden]>
Sent: 08 September 2020 22:51
To: boost_at_[hidden] <boost_at_[hidden]>
Cc: Peter Dimov <pdimov_at_[hidden]>
Subject: Re: [boost] Review Manager needed for Boost.Lambda2
Andrey Semashev wrote:
> I also forgot operator[].
Must be a member. Unary *, however, probably needs to be added. *_1 < *_2 is
a common case.
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk