Boost logo

Boost Users :

Subject: Re: [Boost-users] Small logic::tribool riddle
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2011-03-11 07:14:13


On 11.03.2011 12:53, Thomas Jarosch wrote:
> Hello,
>
> here's a small boost::logic::tribool riddle:
>
> -<snip>-------------------------------------
>
> #include<iostream>
> #include<boost/logic/tribool.hpp>
>
> int main(void)
> {
> boost::logic::tribool foo(boost::logic::indeterminate);
> if (foo != true)
> {
> std::cout<< "reached1\n";
> }
>
> if (foo == boost::logic::indeterminate)
> {
> std::cout<< "reached2\n";
> }
>
> return 0;
> }
>
> -<snap>-------------------------------------
>
> Try to determine the printed result without looking
> at the boost::logic::tribool implementation / documentation.
>
> Intuitive?
If you see tribool as a type that can have the three distinct values
"true", "false", and "indeterminate", then no, it's not intuitive.
If you instead see tribool as having the two values "true" and "false"
and in addition the state "indeterminate", which means "could be true or
false, not sure", then the result of the comparison operators is
intuitive, but the way they behave in conditions still isn't.

Sebastian


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net