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

Paolo Carlini pcarlini@unitus.it
Fri Mar 7 21:25:00 GMT 2003


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
    snextc()
      {
        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()))
      {
        ++__charsread;
        if (_Traits::eq_int_type(__sbout->sputc(_Traits::to_char_type(__c)),
                                 _Traits::eof()))
          break;
        ++__xtrct;
        ++__ret;
        __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.

Thanks,
Paolo.

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



More information about the Libstdc++ mailing list