如果我们有一个地图< int,vector< int> >当地图的红黑树改变或者存储指向矢量或类似物的指针并且不移动它们时移动的向量(否则使用地图将不再是O(lg n),例如,如果我们将push_back元素转换为某些向量)
解决方法
看到这个:
std::map,pointer to map key value,is this possible?
std::map,pointer to map key value,is this possible?
第二个答案:
Section 23.1.2#8 (associative container requirements):
“The insert members shall not affect the validity of iterators and references to the container,and the erase members shall invalidate only iterators and references to the erased elements.”
So yes storing pointers to data members of a map element is guaranteed to be valid,unless you remove that element.
因此,如果保留引用,则无法将数据复制到内存的不同部分.如果是这样的话,我根本没有看到执行任何副本的重点……