16

On this page there is this note:

std::transform does not guarantee in-order application of unary_op or binary_op.

Does this mean that the resulting order of the sequence is not guaranteed to correlate to the order of the input sequence, or, does it mean that, while the order of the final result of the transform is guaranteed, the individual elements could have been created out of order (though they will still appear in-order)?

johnbakers
  • 24,158
  • 24
  • 130
  • 258
  • 1
    Related: http://stackoverflow.com/questions/17356719/why-stdtransform-doesnt-guarantee-the-order-but-for-each-guarantee-the-order – clcto Dec 08 '15 at 23:00

1 Answers1

21

The order of the resulting sequence is fixed. Specifically the standard says:

Effects: Assigns through every iterator i in the range [result,result + (last1 - first1)) a new corresponding value equal to op(*(first1 + (i - result)) or binary_op(*(first1 + (i - result)), *(first2 + (i - result))).

This guarantees that the first element of the result range will be obtained by transforming the first element(s) of the input range(s) and so on. However, the order in which the calls to op are made is not specified.

Brian Bi
  • 111,498
  • 10
  • 176
  • 312