I\'ve got code that looks like this:
for (std::list- ::iterator i=items.begin();i!=items.end();i++)
{
bool isActive = (*i)->update();
/
Iterating backwards avoids the effect of erasing an element on the remaining elements to be traversed:
typedef list- list_t;
for ( list_t::iterator it = items.end() ; it != items.begin() ; ) {
--it;
bool remove =
if ( remove ) {
items.erase( it );
}
}
PS: see this, e.g., regarding backward iteration.
PS2: I did not thoroughly tested if it handles well erasing elements at the ends.