![](/img/trans.png)
[英]Why does std::vector::insert invalidate all iterators after the insertion point
[英]std::deque : What does “insertion and deletion of elements may invalidate iterators” mean?
我正在阅读有关std :: deque容器的内容,文档说明了这一点
在std :: deque中插入和删除元素可能会使其所有迭代器无效
以下是我对上述陈述的理解版本,如果我误解了陈述或遗漏了某些内容,请告诉我
请考虑以下代码
std::deque<int> s;
s.push_back(12);
auto i = s.begin();
s.push_front(45);//After pushing 45 at the back now `i` may be invalid.
这种理解是否正确?
你是对的。 例如之后
std::deque<int> s;
s.push_back(12);
auto i = s.begin();
s.push_front(45)
调用*i
是未定义的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.