[Carpet] RE: associative container erase in for loop

Hartmut Kaiser hartmutkaiser at t-online.de
Sat Feb 5 12:21:08 CET 2005


 
Steve White wrote:

> I thought about it some more.  What puzzles me was that the 
> loop sometimes seemed to work correctly, and sometimes not.  
> Could it have to do with internal ordering?  Like, sometimes 
> due to the way the list is ordered, the for loop incrementer 
> on the erased iterator does the right thing, but sometimes 
> the internal order is different, and the erased iterator 
> doesn't have the right information?...but why...?

That's difficult to tell from the distance. 

As you've stated correctly, the erase operation removes the element from the
container the given iterator is pointing to, thus invalidating this
iterator. The increment operation on an iterator may need access to the
underlying container or it may even not need to have access to it. This
depends on the concrete situation (container implementation details). Maybe
that's the reason, why it sometimes worked and sometimes not.

Regards Hartmut





More information about the developers mailing list