Reputation: 41
I have a C++ STL list of objects in my app that is built on startup and never altered afterwards; is it the case that two independent iterators that point to the same list node always compare equal ?
Upvotes: 4
Views: 1598
Reputation: 254751
Yes. One of the requirements for forward iterators is:
C++11 22.4.5/6: If
a
andb
are both dereferenceable, thena == b
if and only if*a
and*b
are bound to the same object.
All iterators over standard containers are (at least) forward iterators.
Upvotes: 10
Reputation: 72319
Yes, according to cplusplus.com:
http://www.cplusplus.com/reference/std/iterator/ForwardIterator/
Accepts equality/inequality comparisons.
Equal iterators imply the same element is pointed
(I'm not really a fan of this site but I'd trust it here.)
cppreference.com agrees and states more than that, namely all InputIterators (that can be read from) are EqualityComparable, see:
http://en.cppreference.com/w/cpp/concept/InputIterator
Upvotes: 2