本文介绍了为无效的迭代器定义了哪些操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为对,我试图在C ++标准中找到无效迭代器允许的表达式的定义.搜索无效的迭代器"只能在§24.2.1.11中找到一个引用.它说无效的迭代器可能是单一的",但只有声明取消引用它们的状态可能才是未定义的行为.没有进一步的语义.

As a follow-up on a question concerning comparing invalid iterators, I tried to find a definition of the allowed expressions for invalid iterators in the C++ standard. Searching for "invalid iterator" finds only a single reference in §24.2.1.11. It says that invalid iterators may be "singular", but only states that dereferencing them may be undefined behavior. No further semantics is given.

其中一个原始答案表明这是实现定义的行为,但是我认为这通常不能被假定,因为上述段落明确地指的是UB.

One of the original answers suggests that it is implementation-defined behavior, but I think that this cannot be assumed in general because the above mentioned paragraph explicitly refers to UB.

此答案显示任何其他使用无效指针值的行为都具有实现定义的行为".由于向量的迭代器通常被实现为指针,因此我认为比较两个无效的迭代器至少是实现定义的行为.

This answer shows that "Any other use of an invalid pointer value has implementation-defined behavior". Since iterators for vectors are often implemented as pointers, I would argue that comparing two invalid iterators is at least implementation-defined behavior.

有人可以指出标准中有关无效迭代器的语义的相关部分吗?

Could anybody point me to the relevant sections in the standard where the semantics for invalid iterators are defined?

推荐答案

也许[iterator.requirements.general,24.2.1]/6包含您所追求的?

Maybe [iterator.requirements.general, 24.2.1]/6 contains what you're after?

此外,第11段定义了无效的迭代器:

Moreover, invalid iterators are defined by paragraph 11:

因此,无效的迭代器至少与奇异的迭代器一样受约束;具体来说,唯一允许的操作是销毁和分配.

Thus, invalid iterators are at least as constrained as singular iterators; specifically, the only permitted operations are destruction and assignment.

这篇关于为无效的迭代器定义了哪些操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 23:31