Sorry, but this is not possible at all.
The standard defines only two circumstances under which istreambuf_iterator will compare with each other:
- Immediately after creating two iterators from one stream and
- when they are both end stream iterators.
To give an idea of ββwhat this means, consider that the sample code in the standard implements its equal() as follows (N4659, Β§ [istreambuf.iterator.ops] / 5):
Returns: true if and only if both iterators are at the end of the stream, or neither of them is at the end of the stream, regardless of which streambuf object it uses.
So, for any pair of iterators, they will compare unequal if one is at the end of the stream, and the other is not and the end of the stream. For all other cases (both at the end of the stream and at the end of the stream) they will compare equal (even if, for example, they are not even obtained from one stream).
Itβs not entirely clear to me that this requires behavior, but it explicitly allows behavior, and is not just allowed as a random case with a triangle that happened by chance, but as a clearly documented, assumed behavior.
source share