Boost logo

Boost :

From: William E. Kempf (williamkempf_at_[hidden])
Date: 2002-08-02 10:05:21


----- Original Message -----
From: "Rob Stewart" <stewart_at_[hidden]>
To: <boost_at_[hidden]>
Cc: <boost_at_[hidden]>
Sent: Friday, August 02, 2002 9:15 AM
Subject: Re: [boost] 3-state boolean type

> It seems to me that the default ctor should initialize the state to
> indeterminate (or whatever it will be called). Since bool doesn't have a
> default ctor, this is the most logical behavior for tribool.

That depends on what you mean here.

bool b;

This doesn't initialize the value for b, and thus would (fuzzily) suggest
what you're saying. However, this:

bool b();

initializes b to false. So I'd think the default ctor should initialize
the state to false.

> I agree with the sentiments regarding the name. Of those suggested thus
far, I
> like tristate.

I'd call it logic_state. A value of 0 would indicate false, a value of 1
would indicate true, and any other value would be "indeterminate", giving
you the multiple "indeterminate" states people have suggested. Of course
you could templatize this so that logic_state could specify the number of
indeterminate states. As for symbolic names... I wouldn't specify any, and
let the user specify the ones that fit his domain. Alternatively, you could
specify one or more well known sets of symbolic names, such as the suggested
bottom.

> I don't think such a simple type should be overly complicated with support
for
> various numbers of states unless it can be managed by a template and
typedef
> approach. If a tristate version of such a template uses
{true,false,unknown},
> while a quadstate version uses {true,false,maybe_true,maybe_false},
etc. -- that
> is, each variation can have its own names for the values such that they
are
> sensible for the number of states -- then it will be sensible. Without
those
> characteristics, it will be too unwieldy.

I would think you could do this through template mechanisms.

> I can't think of a use for n-state logic at the moment in my current
efforts,
> but several of the suggested uses did resonate with me. For example, I
have
> done GUI programming in the past and a tristate variable would work very
nicely
> to represent the tristate checkboxes in many GUIs. I can imagine that I
might
> have need for a tristate class in the future, so it would be nice to have
it
> available. Unfortunately, I can't say that it is a current or recent
need.

I can second this sentiment.

Bill Kempf


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