std::transform behavior when iterating past container.end()
<p>Code:</p>

<pre><code>static int counter = 0;

int add(int x) {
    counter++;
    return ++x;
}

int main() {
    vector&lt;int&gt; b;
    b.push_back(1);
    b.push_back(1);
    b.push_back(1);

    transform(b.begin(),b.end(),b.begin()+2,add);

    for (vector&lt;int&gt;::iterator it = b.begin(); it != b.end(); it++)
        cout &lt;&lt; (*it) &lt;&lt; endl;
    cout &lt;&lt; "counter: " &lt;&lt; counter &lt;&lt; endl;
}
</code></pre>

<p>For me this compiles with no warnings and prints out:</p>

<pre><code>1
1
2
counter: 3
</code></pre>

<p>What is happening here in the transform function? How is it that add(...) gets called 3 times but b.end() is not overwritten? Is this undefined behavior?</p>
