std::partial_sum( first, last, result, binary_op ) (§26.4.2) is defined as binary_op(binary_op(..., binary_op(*first, *(first + 1)),...), *(first + (i - result))) Ambiguity notwithstanding (what is the first value??), the result of each application is clearly supposed to be forwarded to the next. However, the current implementation does this: typedef typename iterator_traits<_InputIterator>::value_type _ValueType; … __value = __binary_op(__value, *__first); This would be safer: typedef typename _BinaryOperation::result_type _ValueType; Copying *first to *result would require an implicit cast from iterator_traits<_InputIterator>::value_type to _BinaryOperation::result_type, which is not required. Since an additional __binary_op() is not allowed, _ValueType __value( *__first ); might be the best compromise. Anyway, implicit casting the result_type to the input iterator type, as the current implementation does, seems much riskier. The motivating case is pretty simple: I was specifically trying to avoid overflow by summing a std::vector<char> into a std::vector<int>. Furthermore, std::accumulate does correctly avoid overflow.
As far as I can tell, we are already implementing correctly the resolution of DR 539, I went through it one month ago or so: http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#539 If you disagree, please re-open. Thanks.
Reopen...
... to close as duplicate. *** This bug has been marked as a duplicate of 22634 ***