Surprisingly, C++98 and C++11 didn’t say that you can compare a iterator
with a const_iterator
. This leads to LWG issue 179 and LWG issue 2263. Now in C++14, this is explicitly permitted by ยง 23.2.1[container.requirements.general]p7
In the expressions
i == j i != j i < j i <= j i >= j i > j i - j
where
i
andj
denote objects of a container’siterator
type, either or
both may be replaced by an object of the container’sconst_iterator
type referring to the same element with no change in semantics.