
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; }