
AMDG On 04/06/2011 01:50 PM, Jake Brownson wrote:
I love the ideas behind these libs, but I think I need to figure out a bit more before I can use them.
Here's an example that models what I'm trying to do for real as an experiment w/ using phoenix and range. I can't quite get it to build. I think I'm really close. I tried it w/ lambda before I found phoenix and I had to do some ret<> things to get past some errors, but I'm not sure what the equivalent in phoenix is, or if I should really need them.
Also, I think there should be a way to instantiate a vector directly from a range w/o having to use begin() and end() somehow, but I can't find it.
I've tried various approaches with<something> including transformed_range<> and any_range<> and haven't gotten them to work.
If you have a compiler that support C++0x features, <something> can be auto.
The transformed line gives me errors complaining about missing result_type, iterator_category, value_type, difference_type, pointer, reference.
The following works for me with VC++ 2010: Note that if you work through the types, the transform returns a range of B's, not a range of C's. #include <boost/range/adaptor/transformed.hpp> #include <boost/range/algorithm/copy.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(); } }; std::vector<B> CsFromBs(std::vector<B> bs) { std::vector<B> result; boost::copy( bs | boost::adaptors::transformed(boost::phoenix::bind(&C::BFromA, boost::phoenix::bind(&B::a, boost::phoenix::arg_names::arg1))), std::back_inserter(result)); return result; }
I'm using GCC 4.2 on OS X
Thanks!
----
#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(); } };
std::vector<C> CsFromBs(std::vector<B> bs) { <something> cs = bs | boost::adaptors::transformed(boost::phoenix::bind(&C::BFromA, boost::phoenix::bind(&B::a, boost::phoenix::arg_names::arg1))); return std::vector<C>(boost::begin(cs), boost::end(cs)); }
In Christ, Steven Watanabe