This should end up as:
inline streamsize
in_avail()
{
streamsize __ret = this->egptr() - this->gptr();
return (__ret != 0) ? __ret : this->showmanyc();
}
In other words, in_avail() doesn't care if there's anything in some
putback cell; if there is, that's what's available without a call to
underflow(), and that's what this->gptr() points to, so that's all it
reports. In general, you can cut and _cut_ and *cut* the members of
basic_streambuf<> until they are really easy to understand (and fast).
Put all complexity into the virtuals of the derived classes where
speed is less important, because time spent there is amortized over
many characters.
Note that there's no need to test for null pointers because if
one is 0, the others are 0 too and the difference is 0.