Boost logo

Boost :

From: John Maddock (John_Maddock_at_[hidden])
Date: 2001-08-09 06:14:59

>Going back to the original question, I think it may make sense if the
domain of operator== is considered rather than the result of applying
it to out of domain iterators. Consider that there can only be one
value of an input iterator into whatever it is into. There may be
copies of that value, but only one value. Incrementing any one of
the copies invalidates all other copies and they are no longer in
the domain of operator==. Iterators into different things are not
in the domain of operator==.

Not just operator++, operator* effectively invalidates all copies of an
iterator (or at least leaves them in an undefined state), that's why there
is a requirement that calls to operator* and operator++ must alternate. (OK
that's not what the standard says - it says that algorithms must be "single
pass algorithms" and that they can not pass through the same iterator
twice, dereferencing without incrementing counts as a double pass IMO).

>The value returned by operator== for either of the standard input
>iterators is basically meaningless except for comparing to the
>end iterator.


>i == i // true
>*i == *i // true

No, *i gets called twice here, and violates the interface requirements for
input iterators (that calls to operator* and operator++ alternate), the
result is undefined.

>j = i;
>j == i // true
>*j == *i // true

No, calling *i invalidates j, and vice versa (must be "single pass

- John Maddock

Boost list run by bdawes at, gregod at, cpdaniel at, john at