aloha,
I'm currently toying with
boost.lamda and I'm trying to get something to work which I can't seem to do...
First of all, not using lambda, let me show you wnat I'm trying to do:
void a( std::string& v ) {
static int x = 0;
v = boost::lexical_cast(x++);
}
void b( std::string v ) {
std::cout << v << std::endl;
}
int main() {
std::vector<std::string> v(5);
std::for_each( v.being, v.end(), a );
std::for_each( v.being, v.end(), b );
}
So just assign a string representing a number that is incrememnted each time it is assigned to the objects in the vector of strings. Now with boost.lambda I need to get the "a" function working, but can't seem to do so, so far I've tried the following but keep on getting errors, either they don't compile or the variable x is not incremented. I've defined x as an int in the code
// assume for_all is defined as
// #define for_all( o, x ) for_each( o.begin(), o.end(), x )
int x = 0;
for_all( v, (_1 = lexical_cast<std::string>(_2++)(_1, x) ) );
for_all( v, (_1 = bind( lexical_cast<std::string>(), x++ ) ) );
for_all( v, (_1 = lexical_cast<std::string>(x), (_1 += 1)(x) ) );
for_all( v, (_1 = lexical_cast<std::string>(x), (*_1 += 1)(&x) ) );
for_all( v, (_1 = lexical_cast<std::string>(x), boost::lambda::var(x) += 1 ) );
for_all( v, (_1 = lexical_cast<std::string>(x), bind(x,_1) += 1 ) );
for_all( v, _1 = lexical_cast<std::string(x), bind(std::plus<int>(), x) );
for_all( v, _1 = lexical_cast<std::string>(x++) );
Can anyone help me out? Is something like what I'm trying to do even possible with lambda?
Thank you.