Boost logo

Boost :

Subject: Re: [boost] Ternary logic programming
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2015-07-01 22:18:00


On 2/07/2015 12:49, Niall Douglas wrote:
> Out of interest, what do you think of my free function ternary logic
> programming:
>
> tribool t;
> if(true_(t)) { /* true */ }
> else if(false_(t)) { /* false */ }
> else if(unknown(t)) { /* other state */ }
>
> Nobody here seemed to like it. I am looking for something the average
> programmer will notice immediately and not accidentally assume it's
> boolen logic going on here.

FWIW, when working with boost::tribool most code that I've seen/written
deals with it this way:

if (t == true) { /* true */ }
else if (t == false) { /* false */ }
else { /* indeterminate */ }

which is basically the same as yours. Although explicit comparison to
true/false tends to irritate many people (for good reasons, when only
bool is involved).

In some cases this pattern is used, though, which seems to annoy fewer
people:

if (boost::indeterminate(t)) { /* indeterminate */ }
else { /* true/false -- can be passed to bool api or used if (t) */ }


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