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"
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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users