Our friend accumulate.

One thing to notice: it looks like there are a lot of copies going on here. In fact compilers are pretty good at optimizing these away.

I took a look at this with an instrumented class that counts copies, moves, etc, and compared it to a version that used explicit moves: there was no difference except in the single copy of the passed-in init value.