Invalidating list iterator
If you are unfamiliar with the STL, or prefer to do things the "Qt way", you can use these classes instead of the STL classes.The container classes are implicitly shared, they are reentrant, and they are optimized for speed, low memory consumption, and minimal inline code expansion, resulting in smaller executables.If an element is removed should the iteration just cover the remainder of the collection?
For traversing the items stored in a container, you can use one of two types of iterators: Java-style iterators and STL-style iterators.Attempting to work with immutable containers is however a challenge all on its own. The biggest problem is that suddenly I lost access to all the standard containers and iteration syntax. I think it is a good approach, but it really requires full cooperation from the language.At the moment we’re left with one of the fundamental programming constructs being terribly unsafe. I bet that most applications have this issue lurking in at a least a couple of their loops. If you have ideas on how to address this problem, then please let me know.Let’s first give an expanded view of the loop to better see what is happening. There is an iteration variable that starts at the beginning of the collection. If inserting a value into the collection causes reallocation, those pointers are left pointing to the old location. The traditional loop syntax doesn’t have exactly the same problem. If the value is inserted after the current position it will simply be iterated and no issue arise. I know from a few situations that my code doesn’t crash, but that’s it.It won’t have invalid iterators but it may skip or duplicate elements. I choose Python for this reason only: that I don’t know.