Boost logo

Boost :

From: Edward Diener (eddielee_at_[hidden])
Date: 2003-10-04 12:21:06


Douglas Gregor wrote:
> On Saturday 04 October 2003 05:13 am, Edward Diener wrote:
>> Douglas Gregor wrote:
>>> I'd like to request a review of the "tribool" library. It's a little
>>> 3-state
>>> boolean logic library (the third state being "indeterminate", i.e.,
>>> "could be
>>> either true or false") that I've been using for a while in my
>>> research, and
>>> maybe someone else could benefit from it.
>>
>> In what type of situations would one use the "indeterminate" state ?
>> Would you give some practical examples ? It sounds interesting.
>
> Two more:
>
> 1) Comparing intervals in the interval library. When the intervals
> overlap, you don't know how to order the two intervals, so you need a
> third state to represent "don't know", or you need to signal a
> failure. See
> http://www.boost.org/libs/numeric/interval/doc/comparisons.htm
>
> 2) Determining when two pointers alias. "True" if they must alias,
> "false" if they must not alias, and "indeterminate" if they may alias.

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.


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