libstdc++/9424: i/ostream::operator>>/<<(streambuf*) drops characters
Nathan Myers
ncm@cantrip.org
Fri Mar 7 19:56:00 GMT 2003
The following reply was made to PR libstdc++/9424; it has been noted by GNATS.
From: Nathan Myers <ncm@cantrip.org>
To: libstdc++@gcc.gnu.org
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: libstdc++/9424: i/ostream::operator>>/<<(streambuf*) drops characters
Date: Fri, 7 Mar 2003 11:50:55 -0800
On Wed, Feb 26, 2003 at 09:27:32AM -0000, P?tur Run?lfsson wrote:
> I believe the relevant quote is in 27.6.2.5.3 p7, bullet 2:
>
> inserting in the output sequence fails (in which case the
> character to be inserted is not extracted);
>
> So correct code is "as if":
>
> int_type c = sbin->sgetc();
> while (c != traits_type::eof())
> {
> if (sbout->sputc(c) == traits_type::eof())
> break;
> c = sbin->snextc();
> }
>
> Of course, it should be OK to call sgetn if the function *knows*
> that sputc won't fail (for example if epptr() - pptr() is big
> enough).
I wonder if this wouldn't be better implemented using sbumpc:
> int_type c;
> while ((c = sbin->sbumpc()) != traits_type::eof() &&
> (sbout->sputc(c) != traits_type::eof())
> {}
I seem to recall that sbumpc() can be implemented more efficiently
than snextc, although it's just possible I was smoking crack.
Nathan Myers
ncm-nospam@cantrip.org
More information about the Gcc-prs
mailing list