Boost logo

Boost :

From: Rainer Deyke (rdeyke_at_[hidden])
Date: 2021-03-22 09:19:29

On 22.03.21 03:35, Joel de Guzman via Boost wrote:
> The Boost formal review of the Lambda2, authored by Peter Dimov,
> starts Monday, March 22, 2021 to March 31, 2021 (inclusive).
> Documentation:
> Source:

So here's my first impression. It's simple, clean, and elegant.
However, it doesn't appear to solve any problem I have. In a world
where C++ already has "real" lambda expressions as a language feature,
is there any need for another lambda library?

I assume that the appeal of lambda2 is that it involves less typing.
Instead of this:
   [](char c) { return c == '\n'; }
I can type this:
   _1 == '\n'
Fair enough. The latter is clearly shorter, and arguably more readable,
than the former.

However, there are a lot of extra costs associated with the latter:
   - I need to put "using namespace boost::lambda2" in my function (or
at namespace scope, but I try to avoid "using namespace" at namespace
scope where possible).
   - I (and everybody who reads my code) need to be aware of boost::lambda2.
   - For complex lambda expressions, C++ lambdas are more "future-proof"
than boost::lambda2 expressions because I have the full range of the
language available.
   - In C++ lambdas, operators && and || perform short-circuiting just
like in regular C++ code. In boost::lambda2, they do not and cannot.
This is another gotcha to keep in mind when using boost::lambda2.

I use C++ lambdas fairly often. A small but significant portion of
these could be replaced by boost::lambda2 expressions. I am not
convinced that doing so would be an improvement.

Rainer Deyke (rainerd_at_[hidden])

Boost list run by bdawes at, gregod at, cpdaniel at, john at