TITLE: Safe iteration schemes PROBLEM: rmartin@willing.Rational.COM (Bob Martin), 17 Mar 92 Rational, Inc. The issue of iterating safely over the elements within a container is interesting to say the least. When writing a container class, it is very important to specify how to safely iterate over its elements. Iterators are often used, they have the advantage that more than one of them can be active at any one time. Thus you can use several iterators to manage several different scans of the data at the same time. Some container classes provide iteration facilities of their own. In the simplest cases, this will only allow one scan of the data to be active at any given time. However, some container classes maintain a stack of iteration states. This allows clients to start up a new iteration by pushing the old one, and then popping it back when the new iteration is complete. Iteration techniques like this can be much more efficient than query methods. For example, imagine a linked list class which has an operator[](int) query method. By saying list[n] you can access the nth element of the list. Presumably this is accomplished by walking the list to the nth element. The following code is horribly inefficient: for (int i=0; i