incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Brown <mark.g.br...@gmail.com>
Subject Re: stream iterators into different streams compare equal?
Date Wed, 31 Oct 2007 17:14:35 GMT
Travis asked me to forward his response (thanks for the confirmation,
Travis!) to the list. I suppose I should open an issue for this then.

--Mark

vitek@roguewave.com wrote:
> mark.g.brown wrote:
>> Hi all,
>>
>> I have the simple program below that aborts with the latest stdcxx but
>> runs with no problems with g++. Am I missing something or is this a
>> bug in stdcxx?
>>
>> #include <assert.h>
>> #include <iterator>
>> #include <sstream>
>>
>> int main ()
>> {
>>     std::istringstream a ("1");
>>     std::istream_iterator<int> i (a);
>>
>>     std::istringstream b ("2");
>>     std::istream_iterator<int> j (b);
>>
>>     assert (!(i == j));
>> }
>>
>> --Mark
> 
> 24.5 p3 says
> 
> Two end-of-stream iterators are always equal. An end-of-stream iterator is not equal
to a non-end-of-stream iterator. Two non-end-of-stream iterators are equal when they are constructed
from the same stream.
> 
> 24.5.1.1 p1 says
> 
> istream_iterator () Effects: Constructs the end-of-stream iterator.
> 
> 24.5.1.1 p2 says
> 
> istream_iterator(istream_type& s) Effects: Initializes in_stream with s. value may
be initialized during construction or the first time it is referenced.
> 
> 24.5.1.2 p6 says
> 
> template <...> bool operator=(const istream_iterator<...> &x, const istream_iterator<...>
&y) Returns (x.in_stream == y.in_stream) [assuming in_stream is a pointer to the stream
the iterator references].
> 
> Given 24.5.1.1 p1 and p2, it is pretty clear to me that the two iterators are both non-end-of-stream
type, and they are both created on different streams. The streams are different, so the iterators
should not compare equal. I guess one could claim that 24.5.1.2 p6 conflicts with 24.5 p3
because 'end-of-stream' isn't clearly defined, but in this particular case that doesn't matter.
> 
> Travis
> 
> 
> 
> 
> 


Mime
View raw message