Boost logo

Boost :

From: Edward Diener (eddielee_at_[hidden])
Date: 2003-10-04 13:27:32


Douglas Gregor wrote:
> On Saturday 04 October 2003 01:21 pm, Edward Diener wrote:
>> I was thinking of optional<bool> when I saw the note in the optional
>> implementation about tribool. I am not sure there is really much of a
>> practical usage difference between the "indeterminate" state of
>> tribool and the "uninitialized" state of optional<bool>, although it
>> may be argued that there is a conceptual difference. However the use
>> of tribool will eliminate any run-time errors that could be caused
>> by using optional<bool> and incorrectly passing the variable by
>> value, which converts to bool, as opposed to passing the actual bool
>> value. Because of the latter I can see a good reason for having
>> tribool instead of using optional<bool>, despite C++'s well known
>> propensity for not attempting to protect the programmer from his own
>> stupidity.
>
> The two may be conceptually different, if one considers them as
> different chunks of a boolean lattice. Both have the "true" and
> "false" parts of the lattice, but optional<bool> can have the "no
> value" (or "bottom") value whereas tribool can have the
> "any/indeterminate value" (or "top") value.
>
> Granted, those that care about the difference probably want a type
> modeling the whole boolean lattice, and won't care about either
> tribool or optional<bool>. In other words, I agree with what you said
> :)

Those that care about the difference can have optional<tribool> <g>.

Seriously I do think that tribool is worthwhile and would like to see it as
part of Boost, as a conceptual model of a 3-way switch which, now that I
consider it, does occur often enough in areas of programming with which I am
acquainted ( as an exmaple a checkbox can be checked, unchecked, or grayed )


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