Boost logo

Boost :

Subject: Re: [boost] New libraries implementing C++11 features in C++03
From: Rafaël Fourquet (fourquet.d+boost_at_[hidden])
Date: 2011-11-25 10:45:12


>
> I use this construct frequently in my C++11 projects. It can serve to
> make the code more readable. Here's an example of a line of code I
> wrote recently. It makes use of Boost.Range in addition to C++11 lambdas:
>
> vector<message> messages;
> push_back(messages, message_ids | transformed(lookup_message_by_id)
> | filtered(newer_than_one_year)
> | filtered(not_hidden)
> | filtered(satisfies_user_preference));
>
>
I also often use this kind of constructs: it is for me more readable (in
this example) than inline lambdas, and more importantly, named lambdas are
necessary when I have to reuse them in the same enclosing function, for
example:
push_back(hidden_messages, ... | filtered(newer_than_one_year) |
filtered(hidden) | filtered(satisfies_user_preference));

Without c++11 lambdas, I would be very happy to use Boost.Local (whether it
is accepted in Boost or not, I have no opinion on this issue), because
these named lambdas:
- don't need to be tested separately (one-or-two liners)
- only belong to the logic of the enclosing function (I would prefer using
copy/paste to reuse a (small) block of code rather than polluting the outer
scope)
- can bind to local variables, and can be very easily replaced by c++11
lambdas when they become available to me.

Rafaël


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