<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 485: output iterator insufficiently constrained</title>
<meta property="og:title" content="Issue 485: output iterator insufficiently constrained">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue485.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#Resolved">Resolved</a> status.</em></p>
<h3 id="485"><a href="lwg-defects.html#485">485</a>. output iterator insufficiently constrained</h3>
<p><b>Section:</b> 24.3.5.4 <a href="https://wg21.link/output.iterators">[output.iterators]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Chris Jefferson <b>Opened:</b> 2004-10-13 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#output.iterators">active issues</a> in [output.iterators].</p>
<p><b>View all other</b> <a href="lwg-index.html#output.iterators">issues</a> in [output.iterators].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The note on 24.1.2 Output iterators insufficiently limits what can be
performed on output iterators. While it requires that each iterator is
progressed through only once and that each iterator is written to only
once, it does not require the following things:</p>

<p>Note: Here it is assumed that <code>x</code> is an output iterator of type <code>X</code> which
has not yet been assigned to.</p>

<p>a) That each value of the output iterator is written to:
The standard allows:
<code>++x; ++x; ++x;</code>
</p>

<p>
b) That assignments to the output iterator are made in order
<code>X a(x); ++a; *a=1; *x=2;</code> is allowed
</p>

<p>
c) Chains of output iterators cannot be constructed:
<code>X a(x); ++a; X b(a); ++b; X c(b); ++c;</code> is allowed, and under the current
wording (I believe) <code>x,a,b,c</code> could be written to in any order.
</p>

<p>I do not believe this was the intension of the standard?</p>
<p><i>[Lillehammer: Real issue.  There are lots of constraints we
  intended but didn't specify.  Should be solved as part of iterator
  redesign.]</i></p>


<p><i>[
2009-07 Frankfurt
]</i></p>


<blockquote><p>
Bill provided wording according to consensus.
</p></blockquote>

<p><i>[
2009-07-21 Alisdair requests change from Review to Open.  See thread starting
with c++std-lib-24459 for discussion.
]</i></p>


<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Modified wording.  Set to Review.
</p></blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Move to Ready after looking at again in a larger group in Santa Cruz.
</p></blockquote>

<p><i>[
2010 Pittsburgh:
]</i></p>


<blockquote><p>
Moved to <del>NAD Editorial</del><ins>Resolved</ins>.  Rationale added below.
</p></blockquote>



<p><b>Rationale:</b></p>
<p>
Solved by N3066.
</p>


<p id="res-485"><b>Proposed resolution:</b></p>
<p>
Change Table 101 &mdash; Output iterator requirements in 24.3.5.4 <a href="https://wg21.link/output.iterators">[output.iterators]</a>:
</p>
<blockquote>
<table border="1">
<caption>Table 101 &mdash; Output iterator requirements</caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Operational semantics</th>
<th>Assertion/note pre-/post-condition</th>
</tr>

<tr>
<td>
<code>X(a)</code>
</td>
<td>
&nbsp;
</td>
<td>
&nbsp;
</td>
<td>
<code>a = t</code> is equivalent to <code>X(a) = t</code>. note: a destructor is assumed.
</td>
</tr>

<tr>
<td>
<code>X u(a);</code><br/>
<code>X u = a;</code>
</td>
<td>
&nbsp;
</td>
<td>
&nbsp;
</td>
<td>
&nbsp;
</td>
</tr>

<tr>
<td>
<code>*r = o</code>
</td>
<td>
result is not used
</td>
<td>
&nbsp;
</td>
<td>
<ins>
Post: <code>r</code> is not required to be dereferenceable.  <code>r</code> is incrementable.
</ins>
</td>
</tr>

<tr>
<td>
<code>++r</code>
</td>
<td>
<code>X&amp;</code>
</td>
<td>
&nbsp;
</td>
<td>
<code>&amp;r == &amp;++r</code>
<ins>
Post: <code>r</code> is dereferenceable, unless otherwise specified.  <code>r</code> is not required to be incrementable.
</ins>
</td>
</tr>

<tr>
<td>
<code>r++</code>
</td>
<td>
convertible to <code>const X&amp;</code>
</td>
<td>
<code>{X tmp = r;<br/>++r;<br/>return tmp;}</code>
</td>
<td>
<ins>
Post: <code>r</code> is dereferenceable, unless otherwise specified. <code>r</code> is not required to be incrementable.
</ins>
</td>
</tr>

<tr>
<td>
<code>*r++ = o;</code>
</td>
<td>
result is not used
</td>
<td>
&nbsp;
</td>
<td>

</td>
</tr>

</table>
</blockquote>





</body>
</html>
