deque: iterator invalidation

hello

I'm trying to create an iterator invalidation with a deque...but with no success

i'm trying something like:

using namespace std;
deque<int> d;
d.push_back(2);
for (deque<int>::iterator it = d.begin() ; it != d.end() ; ++it)
{
if (*it == 1)
continue;
if (*it % 2 == 0)
d.push_back(*it *2 -1);
}

(this is just an example..this code is not trying to do anything special,just something I just typed)

I've read that a push_back may cause an iterator invalidation,but everything works just fine

thanks
[624 byte] By [oblivious] at [2007-11-20 11:24:27]
# 1 Re: deque: iterator invalidation
Using an invalidated iterator is undefined behavior. It may do what you expect, it may not, but in any case it's wrong. All depends on your implementation of deque, and what sort of errant code you test it with.
Hermit at 2007-11-9 1:25:35 >