unordered_map::iterator->first 的地址会随着后续的插入和删除而改变吗?

Does address of an unordered_map::iterator->first change upon subequent insertions & deletions?

一旦键值对被插入到 unordered_map 中,假设 iter 指向这一对,&iter->first 在这对存在于 [=15= 中的整个生命周期中是不变的]?

键大多是长字符串,所以我想将它们的 iterator->first 地址存储在其他引用位置而不是字符串本身。

没关系,除非你直接擦除元素。

对于std::unordered_map::insert,

If rehashing occurs due to the insertion, all iterators are invalidated. Otherwise iterators are not affected. References are not invalidated. Rehashing occurs only if the new number of elements is greater than max_load_factor()*bucket_count().

对于std::unordered_map::erase

References and iterators to the erased elements are invalidated. Other iterators and references are not invalidated.