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:The error you made is that you mixed boost bind with lambda, which is not
> 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<XML_Element *> * 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) )
> }
>
> }
compatible.
A solution with Phoenix looks like this:
using boost::phoenix::arg_names::_1;
using boost::phoenix::bind;
using boost::phoenix::if_;
if_(bind(&XML_Element::getName, _1) == "Transform")
std::for_each( nodes->begin(), nodes->end(),
[
bind(&HandleStuff::handleTransformations, this, _1)
]
.else_
[
bind(&HandleStuff::handleLinks, this, _1)
]
);