问题描述
关于的这个问题,很显然,标准的精神意味着,例如,deque中间的擦除使所有迭代器无效并且对deque的元素的引用也指代结束迭代器。
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.
然而,I不能在标准的任何地方找到这个显式,严格地说,结束迭代器不是一个元素在容器中的迭代器。
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.
推荐答案
例如,23.1 / 10:
For example, 23.1/10:
我不知道是否可以确定迭代器引用元素在标准中一直使用排除结束迭代器:/
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 :/
正如在注释中所说的,我想这是允许结束迭代器指向容器内的sentinel值。
As said in a comment, I suppose this is to allow end iterators pointing to sentinel values within the container.
例如,一个典型的双向链接 List
实现是创建一个 Node
结构,在 List
中有一个 Node
作为结束节点。
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.
这篇关于结束迭代器无效规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!