Compare C ++ STL List Iterators

I have a list of C ++ STL objects in my application that was created at startup and never changed afterwards; Is it that two independent iterators pointing to the same node list always compare equal?

+4
source share
2 answers

Yes. One of the requirements for advanced iterators is:

C ++ 11 22.4.5 / 6: If a and b are dereferenced, then a == b if and only if *a and *b attached to the same object.

All iterators over standard containers are (at least) forward iterators.

+10
source

Yes, according to cplusplus.com:

http://www.cplusplus.com/reference/std/iterator/ForwardIterator/

Accepts equality / inequality comparisons.
Equal iterators mean that the same element is pointed.

(I am not a fan of this site, but I would trust him here.)


cppreference.com agrees and states, moreover, that all InputIterators (which can be read) are equal to EqualityComparable, see:

http://en.cppreference.com/w/cpp/concept/InputIterator

+2
source

Source: https://habr.com/ru/post/1446455/


All Articles