
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: http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n1958.pdf 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. :-) It doesn't beat Dave's _1 < _2 challenge, but I'm not sure that it has to.