End iterator invalidation rules(结束迭代器失效规则)
问题描述
关于this question on iterator invalidation rules,显然标准的精神意味着,例如,双端队列中间的擦除使所有迭代器和对双端队列元素的引用无效"也指的是结束迭代器.
Regarding this question on iterator invalidation rules, it seems obvious that the spirit of the standard means, for example, that "an erase in the middle of the deque invalidates all the iterators and references to elements of the deque" also refers to the end iterator.
但是,我找不到标准明确说明这一点的任何地方,严格来说,结束迭代器不是容器中 元素 的迭代器.
However, I can't find anywhere that the standard makes this explicit, and strictly speaking the end iterator is not an iterator to an element in the container.
2003 年标准是否在某处明确说明了这一点?
Does the 2003 standard make this clear somewhere?
推荐答案
例如23.1/10:
没有 swap()
函数使任何引用、指针或迭代器引用被交换的容器的元素无效.[ 注意: end()
迭代器不引用任何元素,因此它可能会失效.——尾注]
no
swap()
function invalidates any references, pointers, or iterators referring to the elements of the containers being swapped. [ Note: Theend()
iterator does not refer to any element, so it may be invalidated. —end note ]
我不知道我们是否可以确定引用元素的迭代器在标准中一直被用于排除结束迭代器:/
I do not know if we can be certain that iterator referring to an element has been used consistently in the Standard to exclude end iterators :/
正如评论中所说,我想这是为了允许结束迭代器指向容器内的标记值.
As said in a comment, I suppose this is to allow end iterators pointing to sentinel values within the container.
例如,典型的双向链接 List
实现是创建一个 Node
结构,并在 中按值具有一个
作为结束节点.Node
>List
For example, a typical doubly linked List
implementation is to create a Node
structure, and have one Node
by value within the List
to act as the end node.
这篇关于结束迭代器失效规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:结束迭代器失效规则


基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01