<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2437: iterator_traits&lt;OutIt&gt;::reference can and can't be void</title>
<meta property="og:title" content="Issue 2437: iterator_traits&lt;OutIt&gt;::reference can and can't be void">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2437.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++17">C++17</a> status.</em></p>
<h3 id="2437"><a href="lwg-defects.html#2437">2437</a>. <code>iterator_traits&lt;OutIt&gt;::reference</code> can and can't be <code>void</code></h3>
<p><b>Section:</b> 24.3.5.2 <a href="https://wg21.link/iterator.iterators">[iterator.iterators]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Stephan T. Lavavej <b>Opened:</b> 2014-10-01 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#iterator.iterators">issues</a> in [iterator.iterators].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
24.3.5.2 <a href="https://wg21.link/iterator.iterators">[iterator.iterators]</a>/2 requires an <code>Iterator</code>'s <code>*r</code> to return <code>reference</code>, 
i.e. <code>iterator_traits&lt;X&gt;::reference</code> according to 24.3.1 <a href="https://wg21.link/iterator.requirements.general">[iterator.requirements.general]</a>/11.
<p/>
24.3.5.4 <a href="https://wg21.link/output.iterators">[output.iterators]</a>/1 requires an <code>OutputIterator</code>'s <code>*r = o</code> to do its job, 
so <code>*r</code> clearly can't return <code>void</code>.
<p/>
24.3.2.3 <a href="https://wg21.link/iterator.traits">[iterator.traits]</a>/1 says: "In the case of an output iterator, the types
</p>
<blockquote><pre>
iterator_traits&lt;Iterator&gt;::difference_type
iterator_traits&lt;Iterator&gt;::value_type
iterator_traits&lt;Iterator&gt;::reference
iterator_traits&lt;Iterator&gt;::pointer
</pre></blockquote>
<p>
may be defined as <code>void</code>."
<p/>
This is contradictory. I suggest fixing this by moving the offending requirement down from <code>Iterator</code> to 
<code>InputIterator</code>, and making <code>Iterator</code> say that <code>*r</code> returns an unspecified type. This will 
have the following effects:
</p>
<ul>
<li><p>Output-only iterators will inherit Iterator's "<code>*r</code> returns unspecified" requirement, while 
24.3.2.3 <a href="https://wg21.link/iterator.traits">[iterator.traits]</a>/1 clearly permits reference/etc. to be <code>void</code>.</p></li>
<li><p>Input-or-stronger iterators (whether constant or mutable) are unaffected &mdash; they still have to satisfy 
"<code>*r</code> returns reference", they're just getting that requirement from <code>InputIterator</code> instead of 
<code>Iterator</code>.</p></li>
</ul>

<p><i>[2015-02 Cologne]</i></p>

<p>
EF: This is related to <a href="lwg-defects.html#2438" title="std::iterator inheritance shouldn't be mandated (Status: C++17)">2438</a><sup><a href="https://cplusplus.github.io/LWG/issue2438" title="Latest snapshot">(i)</a></sup>. MC: I'd like to take up 2438 right after this.
<p/>
AM: Does anyone think this is wrong?
<p/>
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.
<p/>
Accepted. And <a href="lwg-defects.html#2438" title="std::iterator inheritance shouldn't be mandated (Status: C++17)">2438</a><sup><a href="https://cplusplus.github.io/LWG/issue2438" title="Latest snapshot">(i)</a></sup> is already Ready. 
</p>


<p id="res-2437"><b>Proposed resolution:</b></p>
<p>
This wording is relative to N3936.
</p>

<ol>
<li><p>In 24.3.5.2 <a href="https://wg21.link/iterator.iterators">[iterator.iterators]</a> Table 106 "Iterator requirements" change as indicated:</p>

<blockquote>
<table border="1">
<caption>Table 106 &mdash; Iterator requirements</caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Operational<br/>semantics</th>
<th>Assertion&#47;note pre-&#47;post-condition</th>
</tr>

<tr>
<td>
<code>*r</code>
</td>
<td>
<del><code>reference</code></del><ins>unspecified</ins>
</td>
<td>
<code></code>
</td>
<td>
<i>pre</i>: <code>r</code> is dereferenceable.
</td>
</tr>

<tr>
<td colspan="4" align="center">
<code>&hellip;</code>
</td>
</tr>
</table>
</blockquote></li>

<li><p>In 24.3.5.3 <a href="https://wg21.link/input.iterators">[input.iterators]</a> Table 107 "Input iterator requirements" change as indicated:</p>

<blockquote>
<table border="1">
<caption>Table 107 &mdash; Input iterator requirements (in addition to Iterator)</caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Operational<br/>semantics</th>
<th>Assertion&#47;note pre-&#47;post-condition</th>
</tr>

<tr>
<td colspan="4" align="center">
<code>&hellip;</code>
</td>
</tr>

<tr>
<td>
<code>*a</code>
</td>
<td>
<ins><code>reference</code>,</ins> convertible to <code>T</code>
</td>
<td>
<code></code>
</td>
<td>
[&hellip;]
</td>
</tr>

<tr>
<td colspan="4" align="center">
<code>&hellip;</code>
</td>
</tr>
</table>
</blockquote></li>
</ol>






</body>
</html>
