Will there be dangling references to map values if it gets resized?

42 Views Asked by At

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();```
0

There are 0 best solutions below