This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libstdc++/9424: i/ostream::operator>>/<<(streambuf*) drops characters


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]