Title
istreambuf_iterator::equal overspecified, inefficient
Status
nad
Section
[istreambuf.iterator.ops]
Submitter
Nathan Myers

Created on 1998-10-15.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

It is not clear that this is a genuine defect. Additionally, the LWG was reluctant to make a change that would result in operator== not being a equivalence relation. One consequence of this change is that an algorithm that's passed the range [i, i) would no longer treat it as an empty range.

Date: 2010-10-21.18:28:33

Proposed resolution:

Replace [istreambuf.iterator::equal], paragraph 1,

-1- Returns: true if and only if both iterators are at end-of-stream, or neither is at end-of-stream, regardless of what streambuf object they use.

with

-1- Returns: true if and only if both iterators are at end-of-stream, regardless of what streambuf object they use.

Date: 2010-10-21.18:28:33

[ Post Summit Daniel adds: ]

Recommend NAD. The proposed wording would violate the axioms of concept requirement EqualityComparable axioms as part of concept InputIterator and more specifically it would violate the explicit wording of [input.iterators]/7:

If two iterators a and b of the same type are equal, then either a and b are both dereferenceable or else neither is dereferenceable.

2009-07 Frankfurt

Agree NAD.

Date: 2010-10-21.18:28:33

[ Summit: ]

Reopened by Alisdair.

Date: 1998-10-15.00:00:00

The member istreambuf_iterator<>::equal is specified to be unnecessarily inefficient. While this does not affect the efficiency of conforming implementations of iostreams, because they can "reach into" the iterators and bypass this function, it does affect users who use istreambuf_iterators.

The inefficiency results from a too-scrupulous definition, which requires a "true" result if neither iterator is at eof. In practice these iterators can only usefully be compared with the "eof" value, so the extra test implied provides no benefit, but slows down users' code.

The solution is to weaken the requirement on the function to return true only if both iterators are at eof.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg767
2010-10-21 18:28:33adminsetmessages: + msg766
2010-10-21 18:28:33adminsetmessages: + msg765
2010-10-21 18:28:33adminsetmessages: + msg764
1998-10-15 00:00:00admincreate