Topic: [Proposal] lambda NEW PROPOSAL (short)
Author: ethouris@guess.if.gmail.com.is.valid.or.invalid (Sektor van Skijlen)
Date: Tue, 31 Oct 2006 18:14:01 GMT Raw View
Ok, in order not to waste your time, this is my proposal, different from the
existing and consistent with the rest of C++.
1. Syntax
Having a function type like this:
typedef int filter_int( int );
We can use it to define a lambda construct:
transform( v1, v2, filter_int( auto i ) { return i*2; } );
Using variadic template feature, a generic function type can be created and
added to the standard library, say, std::lambda.
2. Memory management and closures
State such a function:
int accm( const vector<int>& v )
{
int n = 0;
for_each( v, lambda<void>( int i ) { n += i; } );
return n;
}
The 'n' here is accessed via reference, because the lambda is passed also via
reference:
template<typename F, Container C >
F for_each( C& c, F& f ) { ... }
If the lambda is passed via value, the closure variables are also accessed via
value.
Comments welcome. Should I provide rationale, just follow up or mail me at:
ethouris(at)gmail.com
--
// _ ___ Michal "Sektor" Malecki <sektor(whirl)kis.p.lodz.pl>
\\ L_ |/ `| /^\ ,() <ethouris(O)gmail.com>
// \_ |\ \/ \_/ /\ C++ bez cholesterolu: http://www.intercon.pl/~sektor/cbx
"Java is answer for a question that has never been stated"
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]