
On 11.03.2011 12:53, Thomas Jarosch wrote:
Hello,
here's a small boost::logic::tribool riddle:
-<snip>-------------------------------------
#include<iostream> #include
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