tribool strikes me as one of the oddest corners of Boost. I see how it has some conveniences compared to using an enum but an enum can also be easily expanded represent more than 3 states.
In what real world ways have you put tribool to use?
tribool strikes me as one of the oddest corners of Boost. I see how it has some conveniences compared to using an enum but an enum can also be easily expanded represent more than 3 states.
In what real world ways have you put tribool to use?
There are several real world examples on Google Code Search here.
While I havn't used C++, and hence boost, I have used three-state variables quite extensively in a network application where I need to store state as true/false/pending.
An extra state in any value type can be extremely valuable. It avoids the use of "magic numbers" or extra flags to determine if the value of a variable is "maybe" or "unknown".
Instead of true
or false
, the state of a tribool
is true
, false
, or indeterminate
.
Let's say you have a database that contains a list of customers
and their dateOfBirth
. So you write a function along the lines of :
tribool IsCustomerAdult(customerName);
The function returns:
`true` if the customer is 18 or older; `false` if the customer is less than 18; `indeterminate` if the customer is not in the database (or the dateOfBirth value is not present).
Very useful.
I am a big fan of the Boost library and started using it at company who I have since left. After getting exposure to and using the boost library extensively throughout our project I stumbled on tribool and was considering using for some "Fuzzy Logic" algorithms needing improvements.
I left before I had a chance to get into it, but beyond the "Fuzzy Logic" example, other modules in the system had components with this sort of between state that considering now, I would probably end up using tribool in a decent amount of code if I was still with the company.
-bn
I've seen numerous examples of two booleans being used to represent three possible states, explicitly or otherwise, with the fourth state being silently assumed to be impossible. In at least two cases, I've changed such constructions to use tribool since we started using boost.
I think it is very useful for Language moulding such as OCR applications and Speech synthesis because as you know human languages are ambiguous and they have a lot of Intermediate statuses
looking foreword to improve the current technologies using the tribool