Original Post
Hi, I don't have a copy of the standard so I mostly rely on things like sgi's stl site. I have a bunch of legacy code to deal with that is pretty ugly and I cannot make wholesale changes to it. I'm trying to convert a tick loop that was obviously wrong before into a tick loop that works. It's now storing a vector of objects that have a virtual tick function that can remove the object from the list that it is stored in but often won't. The order of iteration doesn't matter but each item should be ticked exactly once per frame. I cannot change the interface of the Tick call or the fact that things can remove themselves from the vector during the call. After reading notes on vector at the bottom of the sgi site, particularly number 5, I came to the conclusion that if I make sure I have an iterator before the one whose value is being Tick'ed I will be safe. So I tried: (note there is a post increment after "*it" that is not showing up in the preview pane of my firefox) However, Microsoft's VC8 STL assert that the ( it != m_objects.rend() ) uses incompatible iterators after a Tick is reached that removes itself. Is there a problem with my understanding of vector::erase or are Microsoft's checked iterators overly cautious?
ObjectList::reverse_iterator it = m_objects.rbegin();
while( it != m_objects.rend() )
{
Object* o = *it++;
o->Tick();
}