Boost logo

Boost :

From: Kostas Savvidis (kotika98_at_[hidden])
Date: 2021-03-25 13:42:25


>
> On Wed, 24 Mar 2021 at 17:57, Peter Dimov via Boost
> <boost_at_[hidden]> wrote:
>>
>> 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.
>

 Why not add some nice syntactic sugar to the shipping library, i.e. something like this:

template< typename A, typename F> int operator+= (A&& a, F&& f) {return std::count_if( a.cbegin(), a.cend(), f);}
template<typename T, typename F> void operator<<= (T& a, F fun) {
  std::transform(std::begin(a), std::end(a), std::begin(a), fun);
}

so that the lazy people can write:

std::vector<int> v ={3,1,4,1,5,9,2,6,5,3,5,9};
std::cout << "Count even elements: " << (v += (_1 % 2 == 0)) << "\n";

 v <<= _1*_1;
for(auto i : v) std::cout << i << ' '; std::cout << '\n';
std::cout << "Count even elements: " << (v += (_1 % 2 == 0)) << "\n Still three!\n";

Happy April 1st,
K


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk