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.
这篇关于结束迭代器失效规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:结束迭代器失效规则
基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- CString 到 char* 2021-01-01
