|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2021-03-24 16:57:32
Richard Hodges wrote:
> So I settled on this:
>
> std::transform(source.begin(), source.end(), dest.begin(), uppercase < _1);
:-)
FWIW, the "idiomatic" way is to use `std::bind( uppercase, _1 )`, although
in this specific case this can be shortened to just `uppercase`.
> At this point I was presented with a dilemma.
> On the one hand, the library is concise, correct, limited in scope and well
> documented.
> On the other, it doesn't do anything other than remove a few keystrokes in
> the rare case that I want a lambda to do some adding up or taking away.
That's basically what it's about for new code, removing a few keystrokes (if
we discount the use cases related to porting existing Boost.Bind or
Boost.Lambda code to C++14.)
The motivation comes from the various "abbreviated lambda" proposals,
which aim to provide an alternative, more concise, syntax for core language
lambdas. There's a good blog post by Barry Revzin about the verbosity of
C++ lambdas compared to other languages:
https://brevzin.github.io/c++/2020/06/18/lambda-lambda-lambda/
The goal here is to make simple lambdas shorter, not to compete with the
core language lambdas in all cases, which is neither possible nor necessary.
If you just need to say _1 < 0, or _1 < x, or _1 * 2 + 1, the language lambda
boilerplate takes up more than 50% of the whole thing. If, on the other hand,
you need to express something more complex than Lambda2 can handle,
switch to the language lambda.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk