Boost logo

Boost :

From: Jaakko Jarvi (jarvi_at_[hidden])
Date: 2006-04-13 10:49:30

On Apr 12, 2006, at 4:18 PM, Peter Dimov wrote:

> 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
> arguments:
> 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. :-)

The syntactic trouble (which I believe Peter is referring to with the
comment on ambiguities)
is that in a normal function parameter list one can leave out the
parameter name, here we would
be leaving out the parameter type. I think that is fine, but I'd thus
rather make lambdas
look different so that there is no confusion of what kind of
parameter list we are dealing with.

   (e.g. with the syntax <>(x, y) { return x < y; } )

Flagging an ambiguity in the case that the parameter name would be a
type in an outer
scope seems quite brittle.

Cheers, Jaakko

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