Boost logo

Boost :

From: John E. Potter (jpotter_at_[hidden])
Date: 2001-08-08 17:24:02


On Wed, 8 Aug 2001, John Maddock wrote:

> >1. If i == j for an input iterator, what, if anything does it say about
> the
> >relationship between *i and *j. (Given istreambuf_iterator it seems to me
> >that *i and *j may be quite unrelated objects.)
>
> *i, and *j, must return the same value, but operator* is also a mutating
> operation, so *i != *j.

Now I'm confused. My copy of the standard states that operator* is a
const member which calls sgetc. Operator++ is a non-const member
which calls sbumpc.

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==.

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

This seems consistent with streams. Note that cin == cout is both
true and meaningless.

OTOH, for the two standard input iterators (assuming T == T is defined):

i == i // true
*i == *i // true
j = i;
j == i // true
*j == *i // true
++ j;
j == i // don't know and don't care it is out of domain
*j == *i // don't know and don't care it is out of domain

On my implementation the last one is false for istream and true for
istreambuf, but I don't care.

John


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