http://www.cplusplus.com/reference/algorithm/for_each/ Unary function taking an element in the range as argument. This can either be a pointer to a
The semantics of For_each dont fit into what you are trying to do. accumulate does exactly what you are trying, use that instead.