iterating over a tuple
I have a list of heterogeneous objects, e.g. struct Foo { Foo(int v) : value_( v ) {} int value() const { return value_ ; } int value_; }; struct Bar { Bar(int v) : value_( v ) {} int value() const { return value_ ; } int value_; }; int main() { Foo foo(3); Bar bar(7); typedef boost::tuple< Foo, Bar > MyTuple ; MyTuple my_tuple( foo, bar ); return 0; } And now I want to have a function that can accumulate the value sof all the objects in the tuple, e.g. (pseudocode since my problem is exacly that I can't figure out how to code this) template < typename TypleType > int accumulate_values(const TupleType& t) { int acc = 0; for(int i = 0 ; i < t.size() ; ++i ) acc += (get< i >( t )).value(); } Can I do this using mpl (mpl looks great but I can't figure out how to do this). thanks, toon
participants (1)
-
Toon Knapen