Consider the following:
std::unordered_map<int, std::array<float,50>> foo;
...
auto pointerToArray = foo.at(3).data();
I have read this and this. I have the following questions:
- 1)
pointerToArray
falls into which category when referring to the invalidation rules, iterator or reference? - 2) What are the risks that
pointerToArray
will get invalidated (assuming its paired key infoo
is not erased)? - 3) What, if any, difference is there in the answers to these
questions between
unordered_map
andmap
?
Unlike vector
, array
itself will not re-allocate and thus there is not a risk of it changing memory addresses on its own, but as it is inside a unordered/map, the plot thickens.
Update: Found another question that suggests there is no risk of invalidation in this case.