|
Boost : |
From: Petr Kocmid (pkocmid_at_[hidden])
Date: 2002-08-01 22:37:22
Hi Douglas,
> I've just placed a 3-state boolean type in the sandbox,
Your tribool is very cute, however I have a few comments to it:
As it is, it would be probably suitable for checkbox widget with
on/off/maybe semantics on certain GUIs for example.
For other purpose, such as logic circuits emulation, one may require more
than one indeterminate state, such as indeterminate_up.and
indeterminate_down for edge transition states. It would be wise to allow
customization of indeterminate values together with their (perhaps multiple
different) interpretations. Thus, a discrete set fuzzy logic will come out
from it.
publicizing value enum, which is now private will allow using switch. The
question is, if the elegant if(x)..else if(!x)..else... idiom will not be
broken by optimization on some compilers which presume default language
semantics ("warning: unreachable code", sounds familiar?). switch would be
safer for compiler portability, also more readable. This if...else...else
idiom should be definitely part of the test!
safe_bool should assert if indeterminate?
I'd prefer the name change to tristate_bool or multistate_bool respectively
with namespace logic (I mean boost::logic), which certainly will please the
purists. Perhaps, if tristate_bool implementation will remain with
non-customizable indeterminate, multistate_bool could be written more
generic way later on?
Maybe some type traits should be added for such a 3-state too.
Petr Kocmid
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk