Re: [Boost-users] lambda - if_then_else - Compiler can not deduce my Arguments
Hey Thomas
On Mon, Mar 28, 2011 at 11:16 AM, Thomas Heller < thom.heller@googlemail.com> wrote:
On Monday, March 28, 2011 11:34:45 AM Simon Adler wrote:
class XML_Element { public: const std::string & getName(void); };
class HandleStuff { void handleTransformations( XML_Element * node ); void handleLinks( XML_Element * node );
void handle ( std::list
* nodes ) { // what i want to do via boost and which will do the job for (std::list< XML_Element *>::iterator it = nodes->begin(); it != nodes->end(); it++) { if ( (*it)->getName() == "Transform" ) handleTransformations(*it); else handleLinks(*it); } // what i tried std::for_each( nodes->begin(); nodes->end(), boost::lambda::if_then_else( boost::bind(&XML_Element::getName, _1) == std::string("Transform"),
boost::bind<void>(&HandleStuff::loadTransformations, this, _1),
boost::bind<void>(&HandleStuff::loadLinks, this, _1) ) }
}
The error you made is that you mixed boost bind with lambda, which is not compatible.
A solution with Phoenix looks like this:
using boost::phoenix::arg_names::_1; using boost::phoenix::bind; using boost::phoenix::if_;
std::for_each( nodes->begin(), nodes->end(), if_(bind(&XML_Element::getName, _1) == "Transform") [ bind(&HandleStuff::handleTransformations, this, _1) ] .else_ [ bind(&HandleStuff::handleLinks, this, _1) ] );
Yes, it worked. I did not know Phoenix and included now boost/spirit/include/phoenix.hpp - quite big during compilation. It solved my Problem, but if this is a type missmatch - how can i solve this without Phoenix. I have to understand what is going on. I tried to solve this with explicit namespace declarations and replaced _1 via boost::lambda::_1 I also tried to replace all with ::_1 which should explicitly take the declarations from bind/placeholders.hpp thouse are in an unnamed namespace. Please - how can I solve this without using Phoenix? - Not that i don't like your solution but i will understand. Simon
On 28.3.2011 14:17, Simon Adler wrote:
I tried to solve this with explicit namespace declarations and replaced _1 via boost::lambda::_1 I also tried to replace all with ::_1 which should explicitly take the declarations from bind/placeholders.hpp thouse are in an unnamed namespace. Please - how can I solve this without using Phoenix? - Not that i don't like your solution but i will understand.
You should also replace boost::bind with boost::lambda::bind. HTH
You should also replace boost::bind with boost::lambda::bind.
That's it - i did not understand that there is a bind and a lambda::bind and that they are not the same. I learned from books and because the introduce everything early with using namespace declarations i missed that. Thank you and Thomas for your help - i realy got a "boost" in understanding this stuff Simon
participants (2)
-
Juraj Ivančić
-
Simon Adler