On Mon, Jul 9, 2012 at 4:12 AM, Thomas Heller <thom.heller@googlemail.com> wrote:
std::for_each(tokens.begin(), tokens.end(), phx::push_back(&string_tokens,
phx::arg_names::arg1));

This compiles but nothing is placed into string_tokens.  So I'm assuming
the argument from for_each isn't being passed to push_back.  What needs to
changed in this method call?

I am surprised this even compiles. What you want is to pass a reference to string_tokens into the phoenix expression:

You're right.  I didn't copy the line correctly.  There shouldn't be a reference for string_tokens. 
 
phx::push_back(phx::ref(string_tokens, phx::arg_names::arg1)

This fixed the problem.  
 

3.  Can that entire line of question 2 be replaced with the lazy version of
the method calls or does the outer most call need to be a non-lazy method?

phx::for_each(phx::arg_names::arg1, phx::push_back(phx::arg_names::arg2,
phx::arg_names::arg3))(tokens, string_tokens, ???);

If the entire line can be a lazy version then how would I map for_each to
push_back for arg3?
use phx::lambda for the lambda function phx::for_each shall call:

phx::for_each(phx::arg_names::arg1, phx::lambda(phx::local_variable::
_a = phx::ref(string_tokens))[phx::push_back(phx::local_variable::_a, phx::arg_names::_1)])(tokens);

Man that is ugly.  I expected using only pure lazy methods to clean up the call.  Why did the lambda become necessary?  

When reading the documentation for "Lazy Functions" it says "The library is chock full of STL savvy, predefined lazy functions covering the whole of the STL containers, iterators and algorithms."  When you travel to the STL link for algorithms it doesn't mention needing the Phoenix Lambda's to make these work.  Why did the phx::for_each method expect a phx::lambda method instead of being able to take the phx::push_back directly?

After your help with the phx::ref I would have expected the following to work.  It doesn't, I tried.

phx::for_each(phx::ref(tokens), phx::push_back(phx::ref(string_tokens), phx::arg_names::arg1));


So, I have two clean looking method calls but one doesn't work.  I have a pure lazy use of methods that works but doesn't look like a clean call at all.

//1.  Doesn't work but looks clean.  Preferred if it could work.
phx::for_each(phx::ref(tokens), phx::push_back(phx::ref(string_tokens), phx::arg_names::arg1));

//2.  Works and looks clean but has the iterator range as part of the call.
std::for_each(tokens.begin(), tokens.end(), phx::push_back(phx::ref(string_tokens), phx::arg_names::arg1));

//3.  Works but looks more complicated than it should.
phx::for_each(phx::arg_names::arg1, phx::lambda(phx::local_variable::_a = phx::ref(string_tokens))[phx::push_back(phx::local_variable::_a, phx::arg_names::_1)])(tokens);

What is the advantage of method call 3?  If you had to chose between option 2 and 3, why would you chose option 3?


Ryan