Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 76036 invoked from network); 28 Nov 2007 20:05:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Nov 2007 20:05:19 -0000 Received: (qmail 41714 invoked by uid 500); 28 Nov 2007 20:05:07 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 41706 invoked by uid 500); 28 Nov 2007 20:05:07 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 41695 invoked by uid 99); 28 Nov 2007 20:05:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Nov 2007 12:05:07 -0800 X-ASF-Spam-Status: No, hits=-99.8 required=10.0 tests=ALL_TRUSTED,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Nov 2007 20:04:48 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 4FBD6714241 for ; Wed, 28 Nov 2007 12:04:45 -0800 (PST) Message-ID: <10292566.1196280285322.JavaMail.jira@brutus> Date: Wed, 28 Nov 2007 12:04:45 -0800 (PST) From: "Travis Vitek (JIRA)" To: stdcxx-dev@incubator.apache.org Subject: [jira] Issue Comment Edited: (STDCXX-645) stream iterators into different streams compare equal In-Reply-To: <475308.1194106130752.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/STDCXX-645?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12543180 ] vitek edited comment on STDCXX-645 at 11/28/07 12:04 PM: ---------------------------------------------------------------- 24.5.1 p1 says that an istream_iterator becomes an end-of-stream iterator when the end of stream is reached. So checks are required so that two iterators that become end-of-stream iterators will compare equal. #include #include #include int main () { std::istringstream a ("1"); std::istream_iterator i (a); ++i; std::istringstream b ("2"); std::istream_iterator j (b); ++j; assert (i == j); return 0; } This method needs to return true if both iterators are end-of-stream iterators, or they have the same non-null stream pointer. Something like this is more appropriate given the implementation of the other methods template bool operator== (const istream_iterator<_TypeT, _CharT, _Traits, _Distance>& __x, const istream_iterator<_TypeT, _CharT, _Traits, _Distance>& __y) { const bool __x_eos = !__x._C_strm || !*__x._C_strm; const bool __y_eos = !__y._C_strm || !*__y._C_strm; return (__x._C_strm == __y._C_strm) ? true : __x_eos == __y_eos; } The other option would be to change our internal definition of end-of-stream to be istream_iterators with a NULL stream pointer. Then operator++ could be changed to invalidate the stream pointer when the stream reaches eos. I think this would work. istream_iterator& operator++ () { if (_C_strm && !!*_C_strm) *_C_strm >> _C_val; else _C_strm = 0; return *this; } was (Author: vitek): 24.5.1 p1 says that an istream_iterator becomes an end-of-stream iterator when the end of stream is reached. So checks are required so that two iterators that become end-of-stream iterators will compare equal. #include #include #include int main () { std::istringstream a ("1"); std::istream_iterator i (a); ++i; std::istringstream b ("2"); std::istream_iterator j (b); ++j; assert (i == j); return 0; } This method needs to return true if both iterators are end-of-stream iterators, or they have the same non-null stream pointer. Something like this is more appropriate given the implementation of the other methods template bool operator== (const istream_iterator<_TypeT, _CharT, _Traits, _Distance>& __x, const istream_iterator<_TypeT, _CharT, _Traits, _Distance>& __y) { const bool __x_eos = !__x._C_strm || !*__x._C_strm; const bool __y_eos = !__x._C_strm || !*__x._C_strm; return (__x._C_strm == __y._C_strm) ? true : __x_eos == __y_eos; } The other option would be to change our internal definition of end-of-stream to be istream_iterators with a NULL stream pointer. Then operator++ could be changed to invalidate the stream pointer when the stream reaches eos. I think this would work. istream_iterator& operator++ () { if (_C_strm && !!*_C_strm) *_C_strm >> _C_val; else _C_strm = 0; return *this; } > stream iterators into different streams compare equal > ----------------------------------------------------- > > Key: STDCXX-645 > URL: https://issues.apache.org/jira/browse/STDCXX-645 > Project: C++ Standard Library > Issue Type: Bug > Components: 24. Iterators > Affects Versions: 4.1.3, 4.2.0 > Reporter: Mark Brown > > As Travis says in his reply to my post here: > http://www.nabble.com/stream-iterators-into-different-streams-compare-equal--tf4721505.html#a13498487: > 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. > This program aborts with stdcxx but not with gcc: > #include > #include > #include > int main () > { > std::istringstream a ("1"); > std::istream_iterator i (a); > std::istringstream b ("2"); > std::istream_iterator j (b); > assert (!(i == j)); > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.