I have the following code:
std::unordered_map<std::string, std::string> map;
map["k1"] = "v1";
auto& v1 = map["k1"];
map["k2"] = "v2";
After reading https://en.cppreference.com/w/cpp/container/unordered_map#Notes
Notes
The swap functions do not invalidate any of the iterators inside the container, but they do invalidate the iterator marking the end of the swap region.
References and pointers to either key or data stored in the container are only invalidated by erasing that element, even when the corresponding iterator is invalidated.
It looks like v1
can be safely used after inserting new values, even if re-hashing might occur during insertion.
Is my interpretation of this quote correct? May I use references/pointers of the values from the map after modifying the map (obviously erasing the value itself would invalidate the reference/pointer)?