Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2005-03-03 14:06:15

Thorsten Ottosen wrote:

>> The return type already serves a dual purpose: it can store a
>> character or an EOF indication. Unfortunately, with non-blocking or
>> async i/o there are now three possible results of a call to get:
>> 1. A character is successfully retrieved.
>> 2. The end of the stream has been reached.
>> 3. No characters are currently available, but more may be available
>> later.
> isn't this a job for boost::optional<int> ?


    template<typename Source>
    int get(Source&);

should really be

    template<typename Source>
    optional<char> get(Source&);

so maybe I should use optional< optional<char> > ;-)

Seriously, I think the trouble with this suggestion is that EOF and EAGAIN
really deserve equal treatment, whereas with optional<int>, the former would be
represented as part of the int and the latter would be represented as the
absence of an int. If use optional<int> (which I don't dismiss), there will be
lots of tests like

     if (c && c.get() != EOF)

where otherwise you would have

    if (c.good())


Boost list run by bdawes at, gregod at, cpdaniel at, john at