Title
Do output iterators have value types?
Status
cd1
Section
[output.iterators]
Submitter
Dave Abrahams

Created on 2001-06-07.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

The LWG considered two options: change all of the language that seems to imply that output iterators have value types, thus making it clear that output iterators have no value types, or else define value types for output iterator consistently. The LWG chose the former option, because it seems clear that output iterators were never intended to have value types. This was a deliberate design decision, and any language suggesting otherwise is simply a mistake.

A future revision of the standard may wish to revisit this design decision.

Date: 2010-10-21.18:28:33

[ post-Redmond: Jeremy provided wording ]

Date: 2010-10-21.18:28:33

Proposed resolution:

24.1 p1, change

All iterators i support the expression *i, resulting in a value of some class, enumeration, or built-in type T, called the value type of the iterator.

to

All input iterators i support the expression *i, resulting in a value of some class, enumeration, or built-in type T, called the value type of the iterator. All output iterators support the expression *i = o where o is a value of some type that is in the set of types that are writable to the particular iterator type of i.

24.1 p9, add

o denotes a value of some type that is writable to the output iterator.

Table 73, change

*a = t

to

*r = o

and change

*r++ = t

to

*r++ = o
Date: 2001-06-07.00:00:00

Table 73 suggests that output iterators have value types. It requires the expression "*a = t". Additionally, although Table 73 never lists "a = t" or "X(a) = t" in the "expressions" column, it contains a note saying that "a = t" and "X(a) = t" have equivalent (but nowhere specified!) semantics.

According to 24.1/9, t is supposed to be "a value of value type T":

In the following sections, a and b denote values of X, n denotes a value of the difference type Distance, u, tmp, and m denote identifiers, r denotes a value of X&, t denotes a value of value type T.

Two other parts of the standard that are relevant to whether output iterators have value types:

  • 24.1/1 says "All iterators i support the expression *i, resulting in a value of some class, enumeration, or built-in type T, called the value type of the iterator".
  • 24.3.1/1, which says "In the case of an output iterator, the types iterator_traits<Iterator>::difference_type iterator_traits<Iterator>::value_type are both defined as void."

The first of these passages suggests that "*i" is supposed to return a useful value, which contradicts the note in 24.1.2/2 saying that the only valid use of "*i" for output iterators is in an expression of the form "*i = t". The second of these passages appears to contradict Table 73, because it suggests that "*i"'s return value should be void. The second passage is also broken in the case of a an iterator type, like non-const pointers, that satisfies both the output iterator requirements and the forward iterator requirements.

What should the standard say about *i's return value when i is an output iterator, and what should it say about that t is in the expression "*i = t"? Finally, should the standard say anything about output iterators' pointer and reference types?

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg2237
2010-10-21 18:28:33adminsetmessages: + msg2236
2010-10-21 18:28:33adminsetmessages: + msg2235
2001-06-07 00:00:00admincreate