Boost logo

Boost :

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

On Thu, 9 Aug 2001, John Maddock wrote:

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

Make that output_iterator and we can agree that we must use sequences
of the pair *it= and ++it (alias *it++=).

> (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).

Our disagreement. IMO you have not passed *through* an iterator until
it is incremented. When you come *to* an iterator value, you may stay
there and dereference it many times. Once you go through (increment)
it, there is no way back to it, ie. copies are invalid.

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

See below.

> >j = i;
> >j == i // true
> >*j == *i // true
> No, calling *i invalidates j, and vice versa (must be "single pass
> algorithm").

Please note that these statements are about the two standard input
iterators, istream_iterator and istreambuf_iterator. These are
specified and the behaviors I claim are supported by the standard.
We may debate input_iterators in general but not these two.


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