Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-04-12 17:18:10

Brock Peabody wrote:

>> 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() );
>> }
> I like local functions, but one problem I see with this is that it can't
> work in a template. If you make f a template it will be ambiguous
> without a cast or something. If only we could pass functions by name.

The 'f' above is not really a function, it's a function object, a named
lambda. The only difference with Valentin Samko's lambda proposal:

is in the syntax. I'd prefer to not be forced to spell the type of the

    inline bool less( x, y ) { return x < y; }

(and live with the ambiguities when x is a type in an outer scope) but even
with explicit typing as in N1958 it's much better than nothing. :-)

It doesn't beat Dave's _1 < _2 challenge, but I'm not sure that it has to.

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