[quote name='Antheus' timestamp='1328973736' post='4911974']
::iterator types are for iteration. While some may be held on to, it causes aforementioned problems.
In most newer languages, iterators are explicitly checked for modification and will cause failures when trying to use them as references.
Iterators are not identity types and cannot be used for such purpose, even though in some corner cases, depending on implementation, they can temporarily take such role.
This is how iterators work in the real world: their lifespan is limited to some activity that iterates through members of a data structure, and in this small scope one can take care not to invalidate them with inappropriate operations.
If you insist on storing iterators instead of plain pointers or names, you are abusing the standard library and looking for trouble.
[/quote]
Actually, I had programmed my own graph implementation and featured iterators. So I guess I was abusing the
concept of iterator, then. But there's no problem now -- I've since replaced that graph with a new version that uses ID codes to give stable references, like Antheus suggested. Granted, in theory the use of std::map gives a performance hit, but this code is not used in anything performance-critical so that is no problem.