从 std::multimap<> 中删除项目后,我可以继续使用迭代器吗?
即使在调用 multimap::erase() 之后,我还可以继续使用 multimap 迭代器吗? 例如:
Blah::iterator iter;
for ( iter = mm.begin();
iter != mm.end();
iter ++ )
{
if ( iter->second == something )
{
mm.erase( iter );
}
}
这是否应该正确运行,或者迭代器在调用擦除后是否失效? 参考站点,例如 http://www.cplusplus.com/reference/stl/multimap /erase.html 对于迭代器的生命周期或迭代器的构造/破坏性方法的影响这个主题出奇地安静。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://www.sgi.com/tech/stl/Multimap.html
所以它应该看起来像这样:
另请参阅:
如果在从开始到结束迭代时对地图元素调用擦除()会发生
什么
? -the-map-but-the-iterator-must-point-to-the-next-elemen#269717">删除映射中的特定条目,但迭代器必须指向删除后的下一个元素
http://www.sgi.com/tech/stl/Multimap.html
So it should look like this:
Also see:
What happens if you call erase() on a map element while iterating from begin to end?
and
delete a specific entry in the map,but the iterator must point to the next element after the deletion
C++ 标准 23.1.2.8:
这是所有关联容器的共同要求,std::multimap 就是其中之一。
C++ Standard 23.1.2.8:
This is a common requirement for all associative containers, and std::multimap is one of them.