Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost::tribool: odd behaviour, or bug?

Tags:

c++

boost

tribool

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??

like image 645
Roddy Avatar asked Aug 16 '10 17:08

Roddy


1 Answers

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.

like image 61
UncleBens Avatar answered Oct 03 '22 11:10

UncleBens