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 ?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With