|
Boost Users : |
Subject: Re: [Boost-users] lambda - if_then_else - Compiler can not deduce my Arguments
From: Simon Adler (boost_at_[hidden])
Date: 2011-03-28 08:17:05
Hey Thomas
> On Mon, Mar 28, 2011 at 11:16 AM, Thomas Heller <
> thom.heller_at_[hidden]> 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<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) )
>> > }
>> >
>> > }
>>
>> 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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net