|
Boost Users : |
From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2002-04-26 17:45:11
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
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