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

### 2366. `istreambuf_iterator` end-of-stream equality

Section: 25.6.4 [istreambuf.iterator] Status: New Submitter: Hyman Rosen Opened: 2014-02-19 Last modified: 2014-06-17

Priority: 3

View other active issues in [istreambuf.iterator].

View all other issues in [istreambuf.iterator].

View all issues with New status.

Discussion:

Given the following code,

>     #include <sstream>

>     std::stringbuf buf;
>     std::istreambuf_iterator<char> begin(&buf);
>     std::istreambuf_iterator<char> end;

it is not clear from the wording of the Standard whether `begin.equal(end)` must be true. In at least one implementation it is not (CC: Sun C++ 5.10 SunOS_sparc Patch 128228-25 2013/02/20) and in at least one implementation it is (gcc version 4.3.2 x86_64-unknown-linux-gnu).

25.6.4 [istreambuf.iterator] says that `end` is an end-of-stream iterator since it was default constructed. It also says that an iterator becomes equal to an end-of-stream iterator when end of stream is reached by `sgetc()` having returned `eof()`. 99 [istreambuf.iterator::equal] says that `equal()` returns true iff both iterators are end of stream or not end of stream. But there seems to be no requirement that `equal` check for end-of-stream by calling `sgetc()`.

Jiahan Zi at BloombergLP discovered this issue through his code failing to work correctly. Dietmar Kühl has opined in a private communication that the iterators should compare equal.

Proposed resolution: