[tuple] easy way to bind to get
Hi, I would like to bind to the boost::get<N> function for use by transform iterator. This is the pseudo code if get worked like a simple function. std::vector<tuple<int,int,float> > v(2); v[0] = tuple<int,int,float>(2,2,2.2f); v[1] = tuple<int,int,float>(3,3,3.3f); std::accumulate( boost::make_transform_iterator( v.begin(), boost::lambda::bind(&boost::get<1>,_1)), boost::make_transform_iterator( v.end(), boost::lambda::bind(&boost::get<1>,_1)), 0); I find bind is difficult to use for functions that deduce template arguments from function arguments. I thought if I changed boost::get<1> -> boost::get<1,tuple<int,int,float> > That didn't work either. Digging through tuple.hpp makes my head spin. Is there an easy way to do this. Thanks, Chris
http://lists.boost.org/boost-users/2007/01/24529.php Is this what you want? On 10/19/07, Chris Weed <chrisweed@gmail.com> wrote:
Hi, I would like to bind to the boost::get<N> function for use by transform iterator. This is the pseudo code if get worked like a simple function.
std::vector<tuple<int,int,float> > v(2); v[0] = tuple<int,int,float>(2,2,2.2f); v[1] = tuple<int,int,float>(3,3,3.3f); std::accumulate( boost::make_transform_iterator( v.begin(), boost::lambda::bind(&boost::get<1>,_1)), boost::make_transform_iterator( v.end(), boost::lambda::bind(&boost::get<1>,_1)), 0);
I find bind is difficult to use for functions that deduce template arguments from function arguments.
I thought if I changed boost::get<1> -> boost::get<1,tuple<int,int,float>
That didn't work either. Digging through tuple.hpp makes my head spin. Is there an easy way to do this.
Thanks, Chris _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Behalf Of Chris Weed
Hi, I would like to bind to the boost::get<N> function for use by transform iterator.
I don't know the answer to you question, but with overloaded functions or functions that have too many template arguments I sometimes forego binders and write a small struct to invoke them. It might be something like this: template<int Index, class Tuple> struct calls_get_t : std::unary_function<..> { result_type operator()(argument_type arg) { return get<Index>(arg); } }; Maybe boost-pros know a better way. Also I am beginning to look at Fusion which may have some extra functions we can use with tuples. -- John
participants (3)
-
Chris Weed
-
chun ping wang
-
John Femiani