微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c – 地图的第二部分<..,..>稳定吗?

如果我们有一个地图< int,vector< int> >当地图的红黑树改变或者存储指向矢量或类似物的指针并且不移动它们时移动的向量(否则使用地图将不再是O(lg n),例如,如果我们将push_back元素转换为某些向量)

解决方法

看到这个:
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.

因此,如果保留引用,则无法将数据复制到内存的不同部分.如果是这样的话,我根本没有看到执行任何副本的重点……

原文地址:https://www.jb51.cc/c/111033.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐