I recently started using boost lambda and thought that I would try and use it in those places where it will / should facilitate reading.
I have a code similar to the following
std::vector< X * > v;
for ( int i = 0 ; i < 20 ; ++i )
v.push_back( new X() );
and then to remove it ...
std::for_each( v.begin(), v.end(), boost::lamda::delete_ptr() );
Which neatly cleans.
However, I thought that I would have a โlambda-livingโ population of a vector using lambda ... That then the fireworks started ...
I tried..
std::generate_n( v.begin(), 20, _1 = new X() );
but this gave rise to all kinds of compiler errors.
Any ideas that are the best way to "lambda" to achieve this.
thanks Mark.
source
share