Greetings, Some time ago I wrote a blog post, https://pdimov.github.io/blog/2020/07/22/a-c14-lambda-library/, which described how a simple lambda library can be implemented in ~50 lines using the facilities already available in C++14's <functional> standard header. I turned this into a mini-library, https://github.com/pdimov/lambda2, and I'd like to submit that to Boost. I'm looking for a review manager. The library is trivial, so managing the review should be as easy as theoretically possible for a Boost review. Thanks in advance.
On Tue, 8 Sep 2020 at 17:02, Peter Dimov via Boost
I turned this into a mini-library, https://github.com/pdimov/lambda2, and I'd like to submit that to Boost.
I'm looking for a review manager.
FYI, added to the schedule. Best regards, -- Mateusz Loskot, http://mateusz.loskot.net
On 9/8/20 11:00 PM, Peter Dimov via Boost wrote:
Greetings,
Some time ago I wrote a blog post, https://pdimov.github.io/blog/2020/07/22/a-c14-lambda-library/, which described how a simple lambda library can be implemented in ~50 lines using the facilities already available in C++14's <functional> standard header.
I turned this into a mini-library, https://github.com/pdimov/lambda2, and I'd like to submit that to Boost.
I'm looking for a review manager. The library is trivial, so managing the review should be as easy as theoretically possible for a Boost review.
I'll take it. I can be the review manager. I know the subject pretty well and I'd like to take part in Boost again. Regards, -- Joel
Joel de Guzman wrote:
On 9/8/20 11:00 PM, Peter Dimov via Boost wrote:
Greetings,
Some time ago I wrote a blog post, https://pdimov.github.io/blog/2020/07/22/a-c14-lambda-library/, which described how a simple lambda library can be implemented in ~50 lines using the facilities already available in C++14's <functional> standard header.
I turned this into a mini-library, https://github.com/pdimov/lambda2, and I'd like to submit that to Boost.
I'm looking for a review manager. The library is trivial, so managing the review should be as easy as theoretically possible for a Boost review.
I'll take it. I can be the review manager. I know the subject pretty well and I'd like to take part in Boost again.
Thanks!
Joel
Thank you for taking this on. It looks very interesting. I will be trying it out.
I don't suppose we have dated yet for the review.
Best wishes
John
________________________________
From: Boost
Greetings,
Some time ago I wrote a blog post, https://pdimov.github.io/blog/2020/07/22/a-c14-lambda-library/, which described how a simple lambda library can be implemented in ~50 lines using the facilities already available in C++14's <functional> standard header.
I turned this into a mini-library, https://github.com/pdimov/lambda2, and I'd like to submit that to Boost.
I'm looking for a review manager. The library is trivial, so managing the review should be as easy as theoretically possible for a Boost review.
I'll take it. I can be the review manager. I know the subject pretty well and I'd like to take part in Boost again. Regards, -- Joel _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
On Tue, Sep 8, 2020 at 8:02 AM Peter Dimov via Boost
I turned this into a mini-library, https://github.com/pdimov/lambda2, and I'd like to submit that to Boost.
I'll take the reputational hit and ask the stupid questions. Why don't we just slip this into Boost.Core or Boost.Utility and call it a day? I mean, it is 52 lines... Thanks
On Tue, Sep 8, 2020 at 1:36 PM Vinnie Falco via Boost
On Tue, Sep 8, 2020 at 8:02 AM Peter Dimov via Boost
wrote: I turned this into a mini-library, https://github.com/pdimov/lambda2, and I'd like to submit that to Boost.
I'll take the reputational hit and ask the stupid questions. Why don't we just slip this into Boost.Core or Boost.Utility and call it a day? I mean, it is 52 lines...
I find this question 0% stupid. I want to know the same thing. Zach
On 2020-09-08 21:35, Vinnie Falco via Boost wrote:
On Tue, Sep 8, 2020 at 8:02 AM Peter Dimov via Boost
wrote: I turned this into a mini-library, https://github.com/pdimov/lambda2, and I'd like to submit that to Boost.
I'll take the reputational hit and ask the stupid questions. Why don't we just slip this into Boost.Core or Boost.Utility and call it a day? I mean, it is 52 lines...
Boost.Core is a library of components generally useful in other Boost libraries (and possibly Boost users). I don't think this new library will be widely used in Boost libraries. Boost.Utility is more user-oriented, but it has more dependencies than Boost.Lambda2. So if a user wants Lambda2, he will be encumbered with additional dependencies. Personally, I'd prefer to minimize Boost.Core and Boost.Utility and opt for separate libraries, where reasonable. We already have Boost.Lambda and Boost.Phoenix, so having Boost.Lambda2 as a separate library follows the trend.
On 2020-09-08 18:00, Peter Dimov via Boost wrote:
Greetings,
Some time ago I wrote a blog post, https://pdimov.github.io/blog/2020/07/22/a-c14-lambda-library/, which described how a simple lambda library can be implemented in ~50 lines using the facilities already available in C++14's <functional> standard header.
I turned this into a mini-library, https://github.com/pdimov/lambda2, and I'd like to submit that to Boost.
I'm looking for a review manager. The library is trivial, so managing the review should be as easy as theoretically possible for a Boost review.
Looking at the code, I wonder why there is "using namespace std::placeholders". Shouldn't there be a separate namespace for placeholders? (I also think, it goes against our header policies.)
Andrey Semashev wrote:
Looking at the code, I wonder why there is "using namespace std::placeholders". Shouldn't there be a separate namespace for placeholders? (I also think, it goes against our header policies.)
This imports the placeholders into boost::lambda2. There is no scenario in which you want to make the operators available without the placeholders, so without this directive, you'd always need to use both using namespace boost::lambda2; using namespace std::placeholders; This doesn't help anyone. (Operators belong in the namespace of their arguments to be ADL-reachable, so ideally, they would have been in std::placeholders, but I obviously can't place them there.)
On 2020-09-08 22:31, Peter Dimov via Boost wrote:
Andrey Semashev wrote:
Looking at the code, I wonder why there is "using namespace std::placeholders". Shouldn't there be a separate namespace for placeholders? (I also think, it goes against our header policies.)
This imports the placeholders into boost::lambda2. There is no scenario in which you want to make the operators available without the placeholders, so without this directive, you'd always need to use both
using namespace boost::lambda2; using namespace std::placeholders;
This doesn't help anyone.
I see. I was thinking one could use it to compose std::mem_fns or native C++ lambdas without placeholders, but apparently this is not allowed. I noticed a few missing operators: unary +, ++, --, <<, >>, <=>, =, <op>=. Also, unary &, but I'm not sure it's a good idea to add one. I realize that there are no functional objects for those, but the library could define them. Do you plan to add them?
Andrey Semashev wrote:
I noticed a few missing operators: unary +, ++, --, <<, >>, <=>, =, <op>=. Also, unary &, but I'm not sure it's a good idea to add one. I realize that there are no functional objects for those, but the library could define them. Do you plan to add them?
I think that << and >> almost certainly belong there, and I was kind of surprised that <functional> doesn't define function objects for them. Next in line would be unary plus. I'm less sure about the various op-assignments and ++/--. At the moment I'd be inclined to skip them. And of course op= is impossible to add because it must be a member. As for <=>, I admit I haven't considered it at all. I haven't yet updated my thinking to C++20.
On 2020-09-09 00:36, Peter Dimov via Boost wrote:
Andrey Semashev wrote:
I noticed a few missing operators: unary +, ++, --, <<, >>, <=>, =, <op>=. Also, unary &, but I'm not sure it's a good idea to add one. I realize that there are no functional objects for those, but the library could define them. Do you plan to add them?
I think that << and >> almost certainly belong there, and I was kind of surprised that <functional> doesn't define function objects for them. Next in line would be unary plus.
I'm less sure about the various op-assignments and ++/--. At the moment I'd be inclined to skip them. And of course op= is impossible to add because it must be a member.
As for <=>, I admit I haven't considered it at all. I haven't yet updated my thinking to C++20.
I also forgot operator[].
On 2020-09-09 00:51, Peter Dimov via Boost wrote:
Andrey Semashev wrote:
I also forgot operator[].
Must be a member.
Maybe it's worth providing your own placeholders then? Derive from std::placeholders::arg and specialize std::is_placeholder. Should be compatible with std::bind, shouldn't it? I admit, I haven't tried this, though.
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::vectorhttp://www.enseignement.polytechnique.fr/informatique/INF478/docs/Cpp/en/cpp...<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 - polytechniquehttp://www.enseignement.polytechnique.fr/informatique/INF478/docs/Cpp/en/cpp...
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
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
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, 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 );
Peter
There's also std::transform( nums.begin(),nums.end(), nums.begin(), _1 + 1 );
Thank you, that is the answer which is better from the point of view of functional behaviour. I have also been able to do a binary operation as well:
std::transform(nums.begin(),nums.end(),nums.begin(),nums.begin(), (_1 + _2) );
I was ignorant of std::transform although I now see it has a reference on the page for std::for_each!
Thanks again
John
P.S. My email system does not make it easy to do quoting.
________________________________
From: Peter Dimov
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, 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 );
Peter
It would be nice if it also supported
for_each(a.begin(), a.end(), std::cout << _1 << ' ');
which is the starting example given for boost Lambda
https://www.boost.org/doc/libs/1_74_0/doc/html/lambda.html
As was remarked before, there does not seem to be a function object in std to support operator <<.
I am exploring implementing something locally in a copy of lambda2.hpp, so far without success.
John
________________________________
From: Boost
There's also std::transform( nums.begin(),nums.end(), nums.begin(), _1 + 1 );
Thank you, that is the answer which is better from the point of view of functional behaviour. I have also been able to do a binary operation as well:
std::transform(nums.begin(),nums.end(),nums.begin(),nums.begin(), (_1 + _2) );
I was ignorant of std::transform although I now see it has a reference on the page for std::for_each!
Thanks again
John
P.S. My email system does not make it easy to do quoting.
________________________________
From: Peter Dimov
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, 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 ); _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
On 9/30/20 12:37 AM, Fletcher, John P via Boost wrote:
Peter
It would be nice if it also supported
for_each(a.begin(), a.end(), std::cout << _1 << ' ');
For just outputting ranges I would suggest using range_manip: std::cout << boost::log::range_manip(a, ' '); https://www.boost.org/doc/libs/1_74_0/libs/log/doc/html/log/detailed/utiliti... But, as I mentioned before, having operators << and >> would be useful in other contexts.
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
participants (7)
-
Andrey Semashev
-
Fletcher, John P
-
Joel de Guzman
-
Mateusz Loskot
-
Peter Dimov
-
Vinnie Falco
-
Zach Laine