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) */ }