Stl invalidating iterators

I'm surprised that STL uses a chain of blocks.

If neither of these work, perhaps you are using the wrong data type. If you really need to do that, then map isn't the right container. Further, exchanging the pairs' seconds doesn't do anything to the map's internal storage.If you want to be able to do "iterator N" then you need a container that supports random access iterators. The order is only defined internally to be a linear, strict-weak, increasing ordered set. (Copy constructors work wonders.) It is not incongruous to modify a key's associated value.I had always assumed until a couple of years ago that dequeues were implemented as ring buffers and grew like a vector.I did it that way years ago in a Smalltalk interpreter I wrote.It seems like when constructing an iterator a copy of the map is made and changes made to the copy don't affect the map itself.

One solution is keeping track of all the keys with a std::list is the only solution.

Hope this will help Using a for loop to increment an iterator 100 times, doesn't sound fast.

Also just changing the iterator isn't what I want, I want direct access.

Other languages call it a "dictionary" or "associative array." There is no "index" order. do as adir suggests and iterate through the map, element by element, or 2. maps guarantee O(log N) lookups by storing elements in a tree in order.

do as I suggest and know the keys for the elements you want. You can't just go and change elements willy-nilly in a map.

std::deque can be manipulated at the front and even does so without invalidating iterators c.