Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::tribool "if ( someTriboolVar == indeterminate )" semantics is confusing
From: æ£ÄÏÒ ôÒÕÛËÉÎ (ted-xp_at_[hidden])
Date: 2014-03-06 09:16:56


Hello, Peter,

Sure, it is the same logic as when comparing std::numeric_limits<float>::quiet_NaN() values.
Any expression involving indeterminate value should give indeterminance, any comparison should yield falseness, i.e. ((nan==nan) == false) and ((nan!=nan) == false) at the same time.

In other words, you can't say two values to be the same if any (or both) are indeteminate. Equally, you can't say they aren't.

P.S. I sometimes use boost::optional<bool> to get a kind of tri-state value. That works without such surprises.

Best regards,
Fedor Trushkin

06.03.2014, 18:02, "Peter Hackett" <peter.hackett_at_[hidden]>:
> I started using tribool recently. I just discovered that I was using it
> incorrectly.
>
> I had code that did something like:
>
> ššššštribool triboolVar1 = indeterminate;
>
> šššššif ( triboolVar1 == indeterminate ) {
> šššššššššcout << "triboolVar1 is indeterminate" << endl;
> ššššš} šelse {
> šššššššššcout << "triboolVar1 is NOT indeterminate" << endl;
> ššššš}
>
> I was expecting this to print "triboolVar1 is indeterminate".
> However it prints "triboolVar1 is NOT indeterminate".
>
> I ended up looking through "include/boost/logic/tribool.hpp" and after
> a bit of head scratching, I think I understand why this doesn't do
> what I expect:
>
> The above "if" line is "really" (pseudo-code):
>
> if ( operator==(tribool triboolVar1,tribool indeterminate) ) {
>
> where operator== returns a tribool, and (I think)
>
> tribool::operator safe_bool() const
> ššš{
> šššššreturn value == true_value? &dummy::nonnull : 0;
> ššš}
>
> is used to turn the tribool into a bool.
>
> And give that operator== says:
>
> ...
> if (indeterminate(x) || indeterminate(y))
> šššššreturn indeterminate;
> ...
>
> Then clearly no matter what the value of triboolVar1 is, the "if" code
> will be false.
>
> I haven't had any schooling in what (I'm assuming) might be called something
> like "Multi-Level-Logic", but:
>
> Shouldn't an "indeterminate" value equal another "indeterminate" value?
>
> --
> Peter Hackett
> Member of Technical Staff
> IC Manage http://icmanage.com
> phone (408) 358-8191 x6012
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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