Boost logo

Boost Users :

Subject: Re: [Boost-users] [phoenix] [range] I think I'm missing a couple things w/ these libs
From: Joel de Guzman (joel_at_[hidden])
Date: 2011-04-06 20:13:55


On 4/7/2011 6:57 AM, Nathan Crookston wrote:
> On Wed, Apr 6, 2011 at 4:42 PM, Steven Watanabe<watanabesj_at_[hidden]> wrote:
>> I get errors too with 1.46.0. It looks
>> like it's because transform_iterator doesn't
>> use result_of. IIRC, this was fixed /very/
>> recently.
>
> Phoenix v2 is tricky to use with transform due to result_of -- for
> one, there was the bug Steven mentioned with transform_iterator. For
> two, Phoenix v2's return type deduction mechanism is different than
> that used by result_of. Phoenix v3 uses result_of and should then be
> interoperable with boost::adaptors::transformed. For the time being
> it may be better to use boost::bind in this case.

Not quite true. That's a common misconception. Phoenix v2 *does*
support result_of. It's just phoenix::function that does not support
it due to legacy code and backward compat.

As a matter of fact, I took Steven's code and changed the headers to
that of V2 and it compiles:

#include <boost/range/adaptor/transformed.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_bind.hpp>
#include <vector>

class A {};

class B { public: A a; };

class C
{
public:
     static B BFromA(const A& a) { return B(); }
};

template<class T, class Range>
T construct(const Range& r)
{
     return T(boost::begin(r), boost::end(r));
}

std::vector<B> CsFromBs(std::vector<B> bs)
{
     return construct<std::vector<B> >(bs |
         boost::adaptors::transformed(boost::phoenix::bind(&C::BFromA,
         boost::phoenix::bind(&B::a, boost::phoenix::arg_names::arg1))));
}

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://boost-spirit.com

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