Deleting an element from a list in a loop

Tech-Archive recommends: Speed Up your PC by fixing your registry



Will deleting an element from a list while iterating through a loop mess up
the internal pointers? I am thinking of a construct such as this where I
call erase() in the loop:

for (;it != m_list.end(); it++) {

if ((*it)->ThreadFinished() == true) {

...DO STUFF

m_list.erase(it); // delete the element from the list

// Do we need to break out of the loop here?

}

}



Many thanks,


.



Relevant Pages

  • Re: lambda closure question
    ... > What I want to do is pre-load functions with arguments by iterating ... setattr(myclass, item, lamdba self: func(self, item)) ... And that's the correct explanation, ... > reference will always get modified as the loop iterates. ...
    (comp.lang.python)
  • Re: Iterate through member variables of a class
    ... I did that because the OP was asking about iterating through member ... variables of a class by using a while loop. ... you can add or remove elements from the array and the ... So it would be better if I declared the int as a size_t instead? ...
    (comp.lang.cpp)
  • Re: looping questions
    ... this is not a perl problem. ... what is wrong with my IF loop? ... You don't want to use scalar glob here. ... iterating over that result. ...
    (comp.lang.perl.misc)
  • Re: Holding Returned Data in Arrays
    ... whether or not new items are available whilst you loop depends on the ... implementation of the thing you are iterating. ... In the case of Getfiles() you can see that it returns an array. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Another question about performance
    ... Just a simple iterating 10,000,000 of int in intgive u such ... Not on my box - iterating through 10,000,000 ints using foreach ... want to do *something* with the value inside the loop... ...
    (microsoft.public.dotnet.languages.csharp)