This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.

2878. Missing DefaultConstructible requirement for istream_iterator default constructor

Section: 25.6.2.2 [istream.iterator.cons] Status: C++17 Submitter: United States Opened: 2017-02-03 Last modified: 2020-09-06

Priority: Not Prioritized

View all other issues in [istream.iterator.cons].

View all issues with C++17 status.

Discussion:

Addresses US 153

istream_iterator default constructor requires a DefaultConstructible T.

Proposed change:

Add a new p1:

Requires: T is DefaultConstructible.

Previous resolution [SUPERSEDED]:

This wording is relative to N4618.

  1. Modify 25.6.2.2 [istream.iterator.cons] as indicated:

    see below istream_iterator();
    

    -?- Requires: T is DefaultConstructible.

    -1- Effects: Constructs the end-of-stream iterator. If is_trivially_default_constructible_v<T> is true, then this constructor is a constexpr constructor.

    -2- Postconditions: in_stream == 0.

[Kona 2017-02-28: Jonathan provides updated wording as requested by LWG.]

[Kona 2017-03-02]

Accepted as Immediate to resolve NB comment.

Proposed resolution:

This wording is relative to N4618.

  1. Modify 25.6.2 [istream.iterator] as indicated:

    -1- The class template istream_iterator is an input iterator (24.2.3) that reads (using operator>>) successive elements from the input stream for which it was constructed. After it is constructed, and every time ++ is used, the iterator reads and stores a value of T. If the iterator fails to read and store a value of T (fail() on the stream returns true), the iterator becomes equal to the end-of-stream iterator value. The constructor with no arguments istream_iterator() 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 operator* on an end-of-stream iterator is not defined. For any other iterator value a const T& is returned. The result of operator-> on an end-of-stream iterator is not defined. For any other iterator value a const T* is returned. The behavior of a program that applies operator++() to an end-of-stream iterator is undefined. It is impossible to store things into istream iterators. The type T shall meet the DefaultConstructible, CopyConstructible, and CopyAssignable requirements.