As an answer to the question regarding comparing invalid iterators , I tried to find the definition of allowed expressions for invalid iterators in the C ++ standard. A search for an "invalid iterator" finds only one link in Β§24.2.1.11. It says that invalid iterators can be "singular", but only states that their dereferencing can be undefined. No further semantics are specified.
One of the initial answers suggests that this is behavior defined by the implementation, but I think this cannot be accepted at all, because the above paragraph explicitly refers to UB.
This answer shows that "any other use of an invalid pointer value has an implementation-defined behavior." Since iterators for vectors are often implemented as pointers, I would say that comparing two invalid iterators is at least a behavior-driven implementation.
Can someone point me to the relevant sections in the standard where the semantics for invalid iterators are defined?
source share