template<class itType>
class tlp::StableIterator< itType >
Stores the elements of an iterator and iterates on a copy.
THis Iterator stores all the elements accessible by another Iterator into an internal data structure (created at the construction), and then uses this structure for the iteration. Iteration order is the same.
- Warning:
- By default StableIterator takes ownership of the iterator given in parameter, (ie, delete will be called on the input iterator). The deletion takes place when constructing the StableIterator.
This class is really useful when one needs to modify the graph during an iteration. For instance the following code remove all nodes that match the function myfunc(). Using standard iterators for that operations is not possible since we modify the graph.
StableIterator<node> it(graph->getNodes());
while(it.hasNext()) {
node n = it.next();
if (myfunc(n))
graph->delNode(n);
}
- See also:
- stableForEach