For example, 23.1/10:
no swap()
function invalidates any references, pointers, or iterators referring to the elements of the containers being swapped. [ Note: The end()
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.
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…