Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2003-12-30 19:51:09


"Daryle Walker" <darylew_at_[hidden]> wrote in message
news:BC16EDD1.4453%darylew_at_hotmail.com...

>
> The "showmanyc" method returns how many characters are available for
> 'immediate' reading. It is called by the public non-virtual "in_avail"
> method. That method returns the remaining spaces in the read buffer, if
> any, and "this->showmanyc()" otherwise. Your override for "showmanyc"
> should return a positive number corresponding to the number of input
> characters immediately available, -1 if a read will certainly fail, or 0
if
> neither one of these cases can be determined.
>
> Since "basic_nullbuf" doesn't override "showmanyc", it uses the default
> return value of 0. This output-only class must have a 100% input failure
> rate, so should I override that method to return -1 instead? (My test
file
> uses "std::basic_istream<>::readsome", the only stream method that could
> call "showmanyc", so I would have to change that part of my test too.)
>
> --

Looking at the standard, I think either behavior (returning 0 or -1) is
admissible: -1 is a guarantee that a read will fail, 0 is a lack of a
guarantee. Both are consistent with an empty stream. Any attempt to read
from a basic_nullbuf will result in some sort of error eventually, so I
don't see any practial difference.

The only noticeable difference I can think of would be with code which loops
forever, never reading from a stream until it has a guarantee that the read
will succeed. Returning 0 from showmanyc would then result in the program
hanging, while a return value of -1 might result in the detection of the
error condition. Such code is inherently unsafe, so I don't see any reason
to accommodate it.

BTW, I don't understand the prase ' The void source acts as it is empty to
read ' in the docs.

HTH.

Jonathan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk