Address of std::set content

Hi,
i'm using a set to make a symbol table which is shared for usage between different classes.
Can i safely assume that when i insert a string x, that string's address won't change when the map has more things added removed? I did a superficial test adding and removing stuff and the original address kept pointing to that same string.

Is it safe or depends on the implementation, in which case i'd change the set from <string> to <string*>?
Is it safe or depends on the implementation, in which case i'd change the set from <string> to <string*>?

It's safe.

These particular restrictions are called iterator invalidation rules. cppreference has this handy table to summarize:
https://en.cppreference.com/w/cpp/container#Iterator_invalidation
Last edited on
thanks a lot!
Topic archived. No new replies allowed.