|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-10-04 12:46:24
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 :)
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk