I want to know why std::accumulate
(aka reduce) 3rd parameter is needed. For those who do not know what accumulate
is, it\'s used like so:
Because standard library algorithms are supposed to work for arbitrary ranges of (compatible) iterators. So the first argument to accumulate
doesn't have to be begin()
, it could be any iterator between begin()
and one before end()
. It could also be using reverse iterators.
The whole idea is to decouple algorithms from data. Your suggestion, if I understand it correctly, requires a certain structure in the data.