Yes, this will work like you expect.
The Standard guarantees that for any container type, some_container::iterator
can be implicitly converted to some_container::const_iterator
.
The first table in 23.2.1 [container.requirements.general], after defining X
as a container type which contains objects of type T
, has:
Expression: X::iterator
Return type: iterator type whose value type is T
Note: any iterator category that meets the forward iterator requirements. convertible to X::const_iterator
.
Expression: X::const_iterator
Return type: constant iterator type whose value type is T
Note: any iterator category that meets the forward iterator requirements.
(These aren't really expressions, and are types, rather than having "return types", but that's how they're squeezed into the table that is mostly expressions.)
So when you have ciObject2==iObject1
, the compiler notices that the best operator==
is ciObject2==some_container::const_iterator(iObject1)
. And operator==
on two const_iterator
tells you if they refer to the same element.
(I don't see anything explicitly saying that the result of this conversion refers to the same object as the original iterator
. I guess that's just understood.)