Topic: Draft standard confusion on iterators


Author: osinski@valis.cs.nyu.edu (Ed Osinski)
Date: 1995/06/21
Raw View
There seem to be a number of inaccuracies in the section on iterators
in the draft standard.  I would appreciate comments.

The description of iterator categories in the draft standard (24.1,
paragraphs 3-4) seems to contain an obvious contradiction.  I've read
the two paragraphs a number of times, but the error does not appear to
be in my reading.  Since it is relatively short, I'll reproduce the
offending :-) paragraphs in their entirety:

 Forward iterators satisfy all the requirements of the input
 and output iterators and can be used whenever either kind is
 specified; Bidirectional iterators also satisfy all the
 requirements of the forward iterators and can be used whenever
 a forward iterator is specified; Random access iterators also
 satisfy all the requirements of bidirectional iterators and
 can be used whenever a bidirectional iterator is specified.

 Besides its category, a forward, bidirectional, or random
 access iterator can also be mutable or constant depending on
 whether the result of the expression *i behaves as a reference
 or as a reference to a constant.  Constant iterators do not
 satisfy the requirements for output iterators, and the result
 of the expression *i (for constant iterator i) cannot be used
 in an expression where an lvalue is required.

The first paragraph says that forward iterators satisfy all the
requirements of output iterators, while the second paragraph says that
some forward iterators don't satisfy all of those requirements.
Reading further, the tables of required operations for the various
iterator categories shows that forward iterators are in fact not
required to satisfy all the requirements of output iterators.  In
particular, '*a = t' is not required.

I guess the intention is that mutable forward iterators satisfy the
requirements of output iterators, while all forward iterators satisfy
the requirements of input iterators, and similarly for the succeeding
iterator categories.

On a more pedantic note, the table for input iterators states that
the return type of *a is T, while the requirement for forward
iterators states that the return type for *a is T&.  Strictly
speaking, a forward iterator cannot satisfy both of these requirements
at the same time, at least not with the usual meaing of 'return type'.

Here, I guess the intention is that, by 'return type' is meant either
the actual return type or what it can 'decay' to.
--
---------------------------------------------------------------------
 Ed Osinski
 Computer Science Department, New York University
 E-mail:  osinski@cs.nyu.edu
---------------------------------------------------------------------
"No, no, no, don't tug on that. You never know what it might be attached to."
 -- Buckaroo Bonzai to assistant during brain surgery