lambda - if_then_else - Compiler can not deduce my Arguments
Hello,
i need a hint about boost::bind and lambda.
Following (reduced) case:
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
On Monday, March 28, 2011 11:34:45 AM Simon Adler wrote:
Hello,
i need a hint about boost::bind and lambda. Following (reduced) case:
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) ] );
got an error, that the compiler can not deduce a template Argument, but i do not understand what the compiler tries to say.
I am new to bind and lambda and i like it a lot, but in some cases the Error-Messages are hard to understand.
Thank you for any advice. Please understand, that this example is a reduced Version what is realy going on, so i only give the Functions Interfaces.
Simon
participants (2)
-
Simon Adler
-
Thomas Heller