As of the commit d5e9afc on Mar 17,2018 of accumulate.hpp
When passing a range, the init gets std::move
once like this.
T operator()(Rng && rng, T init, Op op = Op{}, P proj = P{}) const
{
return (*this)(begin(rng), end(rng), std::move(init), std::move(op),
std::move(proj));
}
Above code will then call this:
T operator()(I begin, S end, T init, Op op = Op{}, P proj = P{}) const
{
for(; begin != end; ++begin)
init = invoke(op, init, invoke(proj, *begin)); // why do we need this another copy of init?
return init;
}
I wonder why do we need this another copy of init before call invoke?
This init must be overidden any way, right? So why is it not okey to rip it off in the first place?
init = invoke(op, std::move(init), invoke(proj, *begin));