Would reference to values in std::map
or std::unordered_map
be valid/maintained if the map's being inserted new elements or removed from?
For example, is the below code safe? Or would there be dangling references from any edge cases or map implementation variations.
std::map<string,SpecialType> myMap({{"Test",{}},{"something",{}},{"Test3",{}}});
auto pointer = &myMap["Test"];
myMap.erase("something");
pointer->DoSomething();
myMap["newItem"] = SpecialType();
pointer->DoSomething();```