https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104251

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #2)
> (In reply to Felix Köhler from comment #0)
> > you cannot expect to get passed the accumulator value as the first argument
> > to BinOp and the sequence value as the second argument.
> 
> This is correct, you cannot assume that.

The spec for std::accumulate is very precise:

  Computes its result by initializing the accumulator acc with the initial
  value init and then modifies it with acc = std::move(acc) + *i or
  acc = binary_op(std::move(acc), *i) for every iterator i in the range
  [first, last) in order.

It's guaranteed that the accumulator is the first arg, and the range element is
the second.

There is no such wording for std::reduce. That is intentional. Instead it is
defined in terms of GENERALIZED_SUM, defined in [numerics.defn]. The definition
is recursive and allows *both* arguments to the binary_op to be the results of
calling the binary_op. For example, for std::reduce(F, {1, 2, 3, 4), 10) the
result is:
binary_op(a, binary_op(b, c), binary_op(d, e)) where {a, b, c, d, e} is any
permutation of {1, 2, 3, 4, 10}.

Reply via email to