Boost logo

Boost Users :

Subject: Re: [Boost-users] Small logic::tribool riddle
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2011-03-11 09:44:52


On Fri, Mar 11, 2011 at 11:53 AM, Thomas Jarosch <
thomas.jarosch_at_[hidden]> 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?
>
>
Ok, I guessed, got it wrong, read the docs, and still don't get it!
Modifying
your example to...

#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";
   }

   if (boost::logic::indeterminate == boost::logic::indeterminate)
   {
       std::cout << "reached3\n";
   }

   return 0;
}

only prints "reached3", so I can see the logic of second test being
indeterminate rather than true, but then surely the comparing indeterminate
with indeterminate should also be true?

Weird!

- Rob.



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