Boost logo

Boost Users :

From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2002-04-28 15:37:08


On Friday 26 April 2002 13:37, Aleksey Gurtovoy wrote:
> Toon Knapen wrote:
> > I have a list of heterogeneous objects, e.g.
[snip sample code]

> > 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).
>
> It's not exactly a part of MPL (the library doesn't target "run-time" stuff
> to that extent yet; I hope it will some day), but "tuple extension"
> components I wrote some time ago
> (http://groups.yahoo.com/group/boost/files/tuple_ext/tuple_ext-08-nov-01.zi
>p ) allow one to do exactly these kinds of things:
[snip aleksey's solution]

Thanks, I like tuple_ext a _lot_ !
It would be great to have complete STL-like functionality like this.
I created an accumulate function (similar to the STL one) (see below)

I also had to change your for_each. Actually, as in the STL, the
unary-function does not necessarily need to be const so I removed the const.

And finally, I also removed the friend declaration in the tuple_iterator
since it complains about an implicit friend declaration to itself when using
an iterator in a const-member function (gcc 2.95.3 and 3.x)

Plans on adding this tuple_ext to the CVS ?

toon

[Non-text portions of this message have been removed]


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