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.

Yep.

>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
algorithm").

- John Maddock
http://ourworld.compuserve.com/homepages/john_maddock/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk