tags:

views:

61

answers:

1

I'm exploring boost::tribool and was surprised by the following behaviour.

{
using namespace boost;

boost::tribool t(indeterminate);

assert(t==indeterminate);  // This assertion fails!
} 

However, if I do this, the assert passes.

assert(indeterminate(t));

No compiler warnings or errors in either case. Anyone have a good explanation of why this should be??

+3  A: 

I think the answer is in the documentation:

the result of comparing two indeterminate values is indeterminate (not true) - we don't know what the values are, so we can't tell that they are equal;

the indeterminate function can be used to test if a tribool is in an indeterminate state.

UncleBens
And since indeterminate converts implicitly to bool false, the assert fails.
Mark B
"the result of comparing two indeterminate values is indeterminate". Ouch. I guess that makes sense at one level, but it's not intuitive to me.
Roddy