This is the mail archive of the 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

Nathan Myers wrote:

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.

Hi Nathan. Thanks for your feedback.
Indeed (*), the basic loop is much more elegant in terms of sbumpc, and more
efficient too, I guess, since our snextc is implemented in terms of  sbumpc:

       int_type __eof = traits_type::eof();
       return (traits_type::eq_int_type(this->sbumpc(), __eof)
               ? __eof : this->sgetc());

However, in the application I want to count separately the number of succesful
reads (__charsread) and writes (__xtrct) like this:

   __xtrct = __charsread = 0;
   int_type __c = __sbin->sgetc();
   while (!_Traits::eq_int_type(__c, _Traits::eof()))
       if (_Traits::eq_int_type(__sbout->sputc(_Traits::to_char_type(__c)),
       __c = __sbin->snextc();

and can't see a straightforward way to use your suggestion. Can you?

Otherwise, as indicated by Benjamin, for the time being I would check in
this correctness fix with the promise of returning to this function to
streamline it in the _near_ future.


(*) I want to buy crack from your pusher: seems excellent!

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