How to do accumulation on boost::fusion::vector

Hi, I want to do accumulation on boost::fusion::vector. Please refer to the comment in the code. Can somebody let me know how to do it? Thanks, Peng #include <boost/fusion/sequence.hpp> #include <boost/fusion/include/at.hpp> #include <boost/fusion/container.hpp> #include <boost/fusion/iterator.hpp> #include <boost/typeof/typeof.hpp> #include <iostream> struct A { A(int value) : _value(value) { } int _value; }; struct B { B(int value) : _value(value) { } int _value; }; struct C { C(int value) : _value(value) { } int _value; }; template <typename T> int get_it(const T &t) { return t._value; } int main() { BOOST_AUTO(v, boost::fusion::make_vector(A(0), B(1), C(3), B(8), C(7))); // I want to make the following code more generic, the fusion vector length could be anything. // It sum over all the vector elements. int sum = get_it(boost::fusion::at_c<0>(v)) + get_it(boost::fusion::at_c<1>(v)) + get_it(boost::fusion::at_c<2>(v)) + get_it(boost::fusion::at_c<3>(v)) + get_it(boost::fusion::at_c<4>(v)); std::cout << sum << std::endl; }

On Sun, Aug 24, 2008 at 9:37 AM, Peng Yu <pengyu.ut@gmail.com> wrote:
Hi,
I want to do accumulation on boost::fusion::vector. Please refer to the comment in the code. Can somebody let me know how to do it?
Try: http://spirit.sourceforge.net/dl_more/fusion_v2/libs/fusion/doc/html/fusion/... HTH, Stjepan
participants (2)
-
Peng Yu
-
Stjepan Rajko