Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-04-12 16:04:34


Valentin Samko wrote:

> We are currently working on resolving issues raised during the
> committee meeting and hopefully will write a new paper on lambdas.
> Any feedback on this topic will be highly appreciated.

I was looking at the lambda papers recently and I came to the conclusion
that what we actually need is local functions. To pick an example from
N1958:

void foo( myvec& v, const myset& s, int a )
{
// ...
    v.erase(
        std::remove_if(v.begin(), v.end(),
            bool(int x) {
            return std::abs(x) < a
            && s.find(x) != s.end(); }),
        v.end()
    );
}

What I really want is this:

void foo( myvec& v, const myset& s, int a )
{
// ...

    inline bool f( int x ) { return std::abs( x ) < a && s.find( x ) !=
s.end(); }

    v.erase( std::remove_if( v.begin(), v.end(), f ), v.end() );
}

for obvious readability reasons. This syntax also allows me to use a more
descriptive name instead of f, and the consistency with ordinary function
definitions will make it easier to teach. It may be somewhat easier to parse
or specify, but I haven't considered this in detail.


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