Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-05-09 08:41:27


Beman Dawes wrote:
> "Peter Dimov" <pdimov_at_[hidden]> wrote in message
> news:005f01c5547e$3e22aec0$6401a8c0_at_pdimov2...

>> You don't need a name because the user will never test for this
>> category. if( status() & other_flag )
>> {
>> // OK, so what do I do here?
>> }
>>
>> The other categories have expectations attached, so testing for them
>> makes sense.
>
> What you might do in the code above is report the fact that an
> "other" has been discovered, or execute a fallback procedure, or
> whatever.

A fallback only makes sense if a test fails, not when it succeeds.

int r = status();

if( r & directory_flag )
{
    // directory
}
else if( r & file_flag )
{
    // implementation defined, but in general file-like
}
else
{
    // fallback
}

Note that the code is resilient to future changes introducing other
categories.

if( r & other_flag )
{
    // fallback?
}

When the "other" category is split to "device" and "other other", the
meaning of the above code changes. It no longer falls back when it
encounters a device, but it did before.

Explicit tests for "other" or "unknown" are evil and will not pass a
sensible code review anyway.


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