On 07/08/2012 11:16 PM, Ryan wrote:
Hello,
In upgrading from boost 1.39 to 1.47 I changed my use of the Phoenix library (which was within Spirit) to the stand alone Phoenix library. This caused my below code to stop working.
/**** Code Start ***/ static boost::char_separator<char> seperator(":"); boost::tokenizer< boost::char_separator<char> > tokens(s, seperator); //s is a passed in std::string std::vectorstd::string string_tokens;
namespace phx = boost::phoenix; //This line fails to compile now. std::for_each(tokens.begin(), tokens.end(), phx::bind(&std::vectorstd::string::push_back,&string_tokens, phx::arg_names::arg1)); /**** Code Stop ***/
This lead me to three questions.
1. What changed about phoenix bind that caused this not to work any more? I don't know, to be honest. I am surprised this worked at all. push_back is overloaded which can't really be handled that well with bind.
2. I tried using the lazy version of push_back to bypass the bind issue. In the documentation there are not any examples of multiple algorithm and container methods calling each other to show how the arguments of one method is passed to another.
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:
phx::push_back(phx::ref(string_tokens, phx::arg_names::arg1)
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);
Any help for these three questions would really be appreciated.
Hope that helps.
Ryan
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users