<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2878: Missing DefaultConstructible requirement for istream_iterator default constructor</title>
<meta property="og:title" content="Issue 2878: Missing DefaultConstructible requirement for istream_iterator default constructor">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2878.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="2878"><a href="lwg-defects.html#2878">2878</a>. Missing <code>DefaultConstructible</code> requirement for <code>istream_iterator</code> default constructor</h3>
<p><b>Section:</b> 24.6.2.2 <a href="https://wg21.link/istream.iterator.cons">[istream.iterator.cons]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> United States <b>Opened:</b> 2017-02-03 <b>Last modified:</b> 2020-09-06</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#istream.iterator.cons">issues</a> in [istream.iterator.cons].</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><b>Addresses US 153</b></p>

<p><code>istream_iterator</code> default constructor requires a <code>DefaultConstructible T</code>.</p>

<p>
Proposed change:
</p>
<p>
Add a new p1:
</p>
<blockquote><p>
<i>Requires:</i> <code>T</code> is <code>DefaultConstructible</code>.
</p></blockquote>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>

<p>This wording is relative to <a href="https://wg21.link/n4618">N4618</a>.</p>

<ol>
<li><p>Modify 24.6.2.2 <a href="https://wg21.link/istream.iterator.cons">[istream.iterator.cons]</a> as indicated:</p>
<blockquote>
<pre>
<i>see below</i> istream_iterator();
</pre>
<blockquote>
<p>
<ins>-?- <i>Requires:</i> <code>T</code> is <code>DefaultConstructible</code>.</ins>
<p/>
-1- <i>Effects:</i> Constructs the end-of-stream iterator. If <code>is_trivially_default_constructible_v&lt;T&gt;</code> is
<code>true</code>, then this constructor is a <code>constexpr</code> constructor.
<p/>
-2- <i>Postconditions:</i> <code>in_stream == 0</code>.
</p>
</blockquote>
</blockquote>
</li>
</ol>

<p><i>[Kona 2017-02-28: Jonathan provides updated wording as requested by LWG.]</i></p>


<p><i>[Kona 2017-03-02]</i></p>

<p>Accepted as Immediate to resolve NB comment.</p>


<p id="res-2878"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4618">N4618</a>.</p>

<ol>
<li><p>Modify 24.6.2 <a href="https://wg21.link/istream.iterator">[istream.iterator]</a> as indicated:</p>
<blockquote>
<p>
-1- 
The class template <code>istream_iterator</code> is an input iterator (24.2.3)
that reads (using <code>operator>></code>) successive elements from the input
stream for which it was constructed. After it is constructed, and every time
<code>++</code> is used, the iterator reads and stores a value of
<code>T</code>. If the iterator fails to read and store a value of
<code>T</code> (<code>fail()</code> on the stream returns <code>true</code>),
the iterator becomes equal to the end-of-stream iterator value. The constructor
with no arguments <code>istream_iterator()</code> always constructs an
end-of-stream input iterator object, which is the only legitimate iterator to
be used for the end condition. The result of <code>operator*</code> on an
end-of-stream iterator is not defined. For any other iterator value a
<code>const T&amp;</code> is returned. The result of <code>operator-&gt;</code>
on an end-of-stream iterator is not defined. For any other iterator value a
<code>const T*</code> is returned. The behavior of a program that applies
<code>operator++()</code> to an end-of-stream iterator is undefined. It is
impossible to store things into istream iterators.
<ins>The type <code>T</code> shall meet the <code>DefaultConstructible</code>,
<code>CopyConstructible</code>, and <code>CopyAssignable</code> requirements.</ins>
</p>
</blockquote>
</li>

</ol>






</body>
</html>
