std::vector::erase vs "swap and pop"
<p>The "normal" way of deleting an element from a vector goes like this:</p>

<pre><code>vec.erase(vec.begin() + index);
</code></pre>

<p>But in theory it's faster just to do this:</p>

<pre><code>if (vec.size() &gt; 1)
{
    std::iter_swap(vec.begin() + index, vec.end() - 1);
    vec.pop_back();
}
else
{
    vec.clear();
}
</code></pre>

<p>Is there any reason to not use the latter?</p>