inserting into a vector at the front
<pre><code>iterator insert ( iterator position, const T&amp; x );
</code></pre>

<p>is the function declaration of the insert operator of the std::Vector class.</p>

<p>This function's return type is an iterator pointing to the inserted element. My question is, given this return type, what is the most efficient way (this is part of a larger program I am running where speed is of the essence, so I am looking for the MOST computationally efficient way) of inserting at the beginning. Is it the following?</p>

<pre><code>//Code 1
vector&lt;int&gt; intvector;
vector&lt;int&gt;::iterator it;
it = myvector.begin();
for(int i = 1; i &lt;= 100000; i++){
    it = intvector.insert(it,i);
}
</code></pre>

<p>or </p>

<pre><code>//Code 2
vector&lt;int&gt; intvector;
for(int i = 1; i &lt;= 100000; i++){
    intvector.insert(intvector.begin(),i);
}
</code></pre>

<p>Essentially, in Code 2, is the parameter</p>

<pre><code>intvector.begin() 
</code></pre>

<p>"costly" to evaluate computationally as compared to using the returned iterator in Code 1 or should both be equally cheap/costly?</p>

<p>Thanks in advance.</p>
