This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++17 status.
iterator_traits<OutIt>::reference
can and can't bevoid
Section: 24.3.5.2[iterator.iterators]Status:C++17Submitter: Stephan T. LavavejOpened: 2014-10-01Last modified: 2017-07-30
Priority:3
View all otherissues in [iterator.iterators].
View all issues withC++17 status.
Discussion:
24.3.5.2[iterator.iterators]/2 requires anIterator
's*r
to returnreference
, i.e.iterator_traits<X>::reference
according to 24.3.1[iterator.requirements.general]/11.
OutputIterator
's*r = o
to do its job, so*r
clearly can't returnvoid
.24.3.2.3[iterator.traits]/1 says: "In the case of an output iterator, the typesiterator_traits<Iterator>::difference_typeiterator_traits<Iterator>::value_typeiterator_traits<Iterator>::referenceiterator_traits<Iterator>::pointer
may be defined asvoid
."
Iterator
toInputIterator
, and makingIterator
say that*r
returns an unspecified type. This will have the following effects:Output-only iterators will inherit Iterator's "*r
returns unspecified" requirement, while 24.3.2.3[iterator.traits]/1 clearly permits reference/etc. to bevoid
.
Input-or-stronger iterators (whether constant or mutable) are unaffected — they still have to satisfy "*r
returns reference", they're just getting that requirement fromInputIterator
instead ofIterator
.
[2015-02 Cologne]
EF: This is related to2438(i). MC: I'd like to take up 2438 right after this.
AM: Does anyone think this is wrong?GR: Why do we give output iterators to have reference type void? AM: we've mandated that certain output iterators define it as void since 1998. GR: Oh OK, I'm satisfied.Accepted. And2438(i) is already Ready.Proposed resolution:
This wording is relative to N3936.
In 24.3.5.2[iterator.iterators] Table 106 "Iterator requirements" change as indicated:
Table 106 — Iterator requirements Expression Return type Operational
semanticsAssertion/note pre-/post-condition *r
unspecifiedreference
pre: r
is dereferenceable.…
In 24.3.5.3[input.iterators] Table 107 "Input iterator requirements" change as indicated:
Table 107 — Input iterator requirements (in addition to Iterator) Expression Return type Operational
semanticsAssertion/note pre-/post-condition …
*a
reference
, convertible toT
[…] …