Does std::vector::reserve guarantee that the implementation will not invalidate iterators in this case? : <p>Here is a function which intends to:</p>

<p>a) accept a vector of int</p>

<p>b) for each int in the input vector, append the inverse of this int</p>

<p>preconditions: none</p>

<p>postconditions: returned vector's size() is exacly 2 * the input vector's size.</p>

<p>Note that the vector is modified in-place.</p>

<h2>Question:</h2>

<p>Is this function strictly defined behaviour vis-a-vis iterator invalidation during the transform?</p>

<h2>Bonus:</h2>

<p>Is there a better/more succinct/robust way to write it?</p>

<h2>Code:</h2>

<pre><code>std::vector&lt;int&gt; append_negatives(std::vector&lt;int&gt; v)
{
    v.reserve(v.size() * 2);
    std::transform(begin(v), end(v), 
                   back_inserter(v), 
                   [](auto&amp;&amp; x) { return -x; });
    return v;
}
</code></pre>
