#include #include #include #include #include using namespace boost::numeric::ublas; //using namespace std; class Accumulator { vector m_sum; public: Accumulator() : m_sum(3) { m_sum = zero_vector(3); } void operator()(vector v) { m_sum += v; std::cout << m_sum << std::endl; } vector get_sum() { std::cout << "Returning: " << m_sum << std::endl; return m_sum; } }; int main() { std::list > l(10); vector v(3); v(0) = v(1) = v(2) = 1; std::fill(l.begin(), l.end(), v); Accumulator ac; std::for_each(l.begin(), l.end(), ac); std::cout << ac.get_sum() << std::endl; return 0; }