On Mon, Jul 9, 2012 at 3:07 PM, Ryan
On Mon, Jul 9, 2012 at 2:57 PM, Nathan Ridge
wrote: Actually that's not true. Without using Phoenix at all, just using Boost.Range, this is simply:
boost::push_back(string_tokens, tokens);
Interesting, I'll have to take a look at boost range.
As for your question about why Phoenix for_each requires a lambda, I'm
afraid I don't understand Phoenix well enough to answer that. Perhaps Thomas can help us.
Lets hope he weighs in then. I would really like to understand this sticking point.
I'm pretty sure it's a scoping issue. Your inner and outer arg1's should actually bind at different times to different objects, and the only way to signify that is to use scope the inner arg1 in a phx::lambda construct. I don't remember exactly what you were trying to do, but I believe it was something like phx::for_each(arg1, phx::push_back(dest, arg1))(srce) which evaluates to approximately for_each(srce, F) where F(x) evaluates dest.push_back(srce) (regardless of x) every time, since the arg1 in phx::push_back(dest, arg1) is immediately bound to srce. phx::lambda effectively delays this binding to give you what you want: phx::for_each(arg1, phx::lambda(phx::push_back(dest, arg1)))(srce) => for_each(srce, phx::push_back(dest, arg1)) Note that my syntax is way off here, but this scoping issue is present not just in Boost.Phoenix but also Boost.MPL and probably Boost.Bind/Std.Bind. Also consider reading up on de Bruijn indices on wikipedia; at some point in the past on this list, someone proposed using de Bruijn placeholders to avoid phx::lambda (and Phoenix local variables) acrobatics. HTH, - Jeff