I'm aware erasing will invalidate iterators at and after the point of the erase. Consider:
std::vector<int> vec = {1, 2, 3, 4, 5};
std::vector<int>::iterator it = vec.end() - 1; //last element
vec.erase(vec.begin()); //shift everything one to the left, 'it' should be the new 'end()' ?
std::cout << (it == vec.end()); //not dereferencing 'it', just comparing, UB ?
Is it undefined behavior to compare (not dereference) an invalidated iterator (it
in this case)? If not, is it == vec.end()
guaranteed to hold true?
Edit: from the top answer it looks like this is UB if only it
is a singular value. But from What is singular and non-singular values in the context of STL iterators? it seems like it
is (or was) associated with the container hence making it
non-singular.
I'd appreciate further analysis on this, thank you.