Boost logo

Boost Users :

Subject: Re: [Boost-users] [phoenix] [range] I think I'm missing a couple things w/ these libs
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-04-06 18:06:01


AMDG

On 04/06/2011 02:52 PM, Jake Brownson wrote:
>> If you have a compiler that support C++0x features,
>> <something> can be auto.
>
> Yeah I was thinking the same thing, I don't think I should stray into
> 0x land w/ this stuff yet.
>
> I thought about using a copy, and not to get too picky but it'd be so
> much slicker if I could just instantiate the vector inline. If I could
> write down the type I could at least create a helper that does the
> begin/end calls. I figure at least the way I was trying to do it was 2
> lines instead of 3, and didn't have a non-const var lying around.
>

Well, how about this version:
tested with msvc 10.0 and gcc 4.5.1

#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/any_range.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))));
}

>> The following works for me with VC++ 2010:
>
> I'm getting the same build errors with what you provided... I guess my
> compiler has issues with this.

Maybe. I'm using the most recent development trunk.

> I'm using XCode 4 w/ GCC 4.2 and boost
> 1.46.1. I get the same errors when I try LLVM 2.0. I thought I was
> doing it about right :(.
>

What version of phoenix are you using?
It's obviously not from 1.46.1, since
the first official release of Phoenix 3
will be in 1.47.

In Christ,
Steven Watanabe


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