Which operations are defined for invalid iterators?

前端 未结 1 539
盖世英雄少女心
盖世英雄少女心 2021-01-21 09:20

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

相关标签:
1条回答
  • 2021-01-21 09:43

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

    Results of most expressions are undefined for singular values; the only exceptions are destroying an iterator that holds a singular value, the assignment of a non-singular value to an iterator that holds a singular value, and, for iterators that satisfy the DefaultConstructible requirements, using a value-initialized iterator as the source of a copy or move operation. [Note: This guarantee is not offered for default initialization, although the distinction only matters for types with trivial default constructors such as pointers or aggregates holding pointers. — end note] In these cases the singular value is overwritten the same way as any other value. Dereferenceable values are always non-singular.

    Moreover, invalid iterators are defined by paragraph 11:

    An invalid iterator is an iterator that may be singular.

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

    0 讨论(0)
提交回复
热议问题