This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: libstdc++/9424: i/ostream::operator>>/<<(streambuf*) drops characters
- From: Nathan Myers <ncm at cantrip dot org>
- To: libstdc++ at gcc dot gnu dot org
- Cc: gcc-gnats at gcc dot gnu dot org
- Date: Fri, 7 Mar 2003 11:50:55 -0800
- Subject: Re: libstdc++/9424: i/ostream::operator>>/<<(streambuf*) drops characters
- References: <07D05A69A3D0C14FAEA60C3ACE8E5564028F5533@nike.hir.is>
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 at cantrip dot org