title: Is it valid to use std::transform with std::back_inserter?
body: <p>Cppreference has this example code for <a href="https://en.cppreference.com/w/cpp/algorithm/transform" rel="noreferrer"><code>std::transform</code></a>:</p>
  
  <pre><code>std::vector&lt;std::size_t&gt; ordinals;
  std::transform(s.begin(), s.end(), std::back_inserter(ordinals),
                 [](unsigned char c) -&gt; std::size_t { return c; });
  </code></pre>
  
  <p>But it also says:</p>
  
  <blockquote>
    <p><code>std::transform</code> does not guarantee in-order application of <code>unary_op</code> or <code>binary_op</code>. To apply a function to a sequence in-order or to apply a function that modifies the elements of a sequence, use <code>std::for_each</code>.</p>
  </blockquote>
  
  <p>This is presumably to allow parallel implementations. However the third parameter of <code>std::transform</code> is a <a href="https://en.cppreference.com/w/cpp/named_req/OutputIterator" rel="noreferrer"><code>LegacyOutputIterator</code></a> which has the following postcondition for <code>++r</code>:</p>
  
  <blockquote>
    <p>After this operation <code>r</code> is not required to be incrementable and any copies of the previous value of <code>r</code> are no longer required to be dereferenceable or incrementable.</p>
  </blockquote>
  
  <p>So it seems to me that the assignment of the output <em>must</em> happen in order. Do they simply mean that the application of <code>unary_op</code> may be out of order, and stored to a temporary location, but copied to the output in order? That doesn't sound like something you'd ever want to do.</p>
  
  <p>Most C++ libraries haven't actually implemented parallel executors yet, but Microsoft has. I'm pretty sure <a href="https://github.com/microsoft/STL/blob/da0d8cfdef750abd55e1874b81252b99934c1329/stl/inc/execution#L2336" rel="noreferrer">this</a> is the relevant code, and I <em>think</em> it calls <a href="https://github.com/microsoft/STL/blob/da0d8cfdef750abd55e1874b81252b99934c1329/stl/inc/execution#L869" rel="noreferrer">this <code>populate()</code> function</a> to record iterators to chunks of the output, which surely isn't a valid thing to do because  <code>LegacyOutputIterator</code> can be invalidated by incrementing copies of it.</p>
  
  <p>What am I missing?</p>