Nearly. The functor must be a binary operator that takes the return type as the first and the range type as the second argument:
x = Functor(init, *it++); x = Functor(x, *it++); x = Functor(x, *it++); // ... until it == end
Thus, you do not need a full-fledged functor, a simple function will do:
int map_acc(int lhs, const std::pair<int, int> & rhs) { return lhs + rhs.second; } const int sum = std::accumulate(m.begin(), m.end(), 0, map_acc);
source share