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

245. Which operations on istream_iterator trigger input operations?

Section: 25.6.2 [istream.iterator] Status: NAD Submitter: Andrew Koenig Opened: 2000-05-02 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [istream.iterator].

View all issues with NAD status.

Discussion:

I do not think the standard specifies what operation(s) on istream iterators trigger input operations. So, for example:

        istream_iterator<int> i(cin);

        int n = *i++;

I do not think it is specified how many integers have been read from cin. The number must be at least 1, of course, but can it be 2? More?

Rationale:

The standard is clear as written: the stream is read every time operator++ is called, and it is also read either when the iterator is constructed or when operator* is called for the first time. In the example above, exactly two integers are read from cin.

There may be a problem with the interaction between istream_iterator and some STL algorithms, such as find. There are no guarantees about how many times find may invoke operator++.