17

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)?

2
  • 1
    Related: stackoverflow.com/questions/17356719/… Commented Dec 8, 2015 at 23:00
  • The same question and the same answer is true for std::ranges::transform(), defined from C++20 on. See link, section 25.7.4 footnote 1...1.3.4 . @johnbakers Maybe you want to update your question. Commented Aug 7 at 15:11

1 Answer 1

22

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.