]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/logic/test/tribool_test.cpp
1 // Copyright Douglas Gregor 2002-2003. Use, modification and
2 // distribution is subject to the Boost Software License, Version
3 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/logic/tribool.hpp>
7 #include <boost/test/minimal.hpp>
10 int test_main(int, char*[])
12 using namespace boost::logic
;
15 tribool
y(true); // true
16 tribool
z(indeterminate
); // indeterminate
19 BOOST_CHECK(x
== false);
20 BOOST_CHECK(false == x
);
21 BOOST_CHECK(x
!= true);
22 BOOST_CHECK(true != x
);
23 BOOST_CHECK(indeterminate(x
== indeterminate
));
24 BOOST_CHECK(indeterminate(indeterminate
== x
));
25 BOOST_CHECK(indeterminate(x
!= indeterminate
));
26 BOOST_CHECK(indeterminate(indeterminate
!= x
));
28 BOOST_CHECK(!(x
!= x
));
29 BOOST_CHECK(!(x
&& true));
30 BOOST_CHECK(!(true && x
));
31 BOOST_CHECK(x
|| true);
32 BOOST_CHECK(true || x
);
35 BOOST_CHECK(y
== true);
36 BOOST_CHECK(true == y
);
37 BOOST_CHECK(y
!= false);
38 BOOST_CHECK(false != y
);
39 BOOST_CHECK(indeterminate(y
== indeterminate
));
40 BOOST_CHECK(indeterminate(indeterminate
== y
));
41 BOOST_CHECK(indeterminate(y
!= indeterminate
));
42 BOOST_CHECK(indeterminate(indeterminate
!= y
));
44 BOOST_CHECK(!(y
!= y
));
46 BOOST_CHECK(indeterminate(z
|| !z
));
47 BOOST_CHECK(indeterminate(z
== true));
48 BOOST_CHECK(indeterminate(true == z
));
49 BOOST_CHECK(indeterminate(z
== false));
50 BOOST_CHECK(indeterminate(false == z
));
51 BOOST_CHECK(indeterminate(z
== indeterminate
));
52 BOOST_CHECK(indeterminate(indeterminate
== z
));
53 BOOST_CHECK(indeterminate(z
!= indeterminate
));
54 BOOST_CHECK(indeterminate(indeterminate
!= z
));
55 BOOST_CHECK(indeterminate(z
== z
));
56 BOOST_CHECK(indeterminate(z
!= z
));
58 BOOST_CHECK(!(x
== y
));
60 BOOST_CHECK(indeterminate(x
== z
));
61 BOOST_CHECK(indeterminate(x
!= z
));
62 BOOST_CHECK(indeterminate(y
== z
));
63 BOOST_CHECK(indeterminate(y
!= z
));
65 BOOST_CHECK(!(x
&& y
));
67 BOOST_CHECK(!(x
&& z
));
68 BOOST_CHECK(indeterminate(y
&& z
));
69 BOOST_CHECK(indeterminate(z
&& z
));
70 BOOST_CHECK(indeterminate(z
|| z
));
71 BOOST_CHECK(indeterminate(x
|| z
));
74 BOOST_CHECK(indeterminate(y
&& indeterminate
));
75 BOOST_CHECK(indeterminate(indeterminate
&& y
));
76 BOOST_CHECK(!(x
&& indeterminate
));
77 BOOST_CHECK(!(indeterminate
&& x
));
79 BOOST_CHECK(indeterminate
|| y
);
80 BOOST_CHECK(y
|| indeterminate
);
81 BOOST_CHECK(indeterminate(x
|| indeterminate
));
82 BOOST_CHECK(indeterminate(indeterminate
|| x
));
84 // Test the if (z) ... else (!z) ... else ... idiom
117 #ifndef BOOST_NO_CXX11_CONSTEXPR
118 constexpr bool res_ors
= indeterminate(false || tribool(false) || false || indeterminate
); // true
119 BOOST_CHECK(res_ors
);
120 char array_ors
[res_ors
? 2 : 3];
121 BOOST_CHECK(sizeof(array_ors
) / sizeof(char) == 2);
123 constexpr bool res_ands
= !indeterminate(!(true && tribool(true) && true && indeterminate
)); // false
124 BOOST_CHECK(!res_ands
);
125 char array_ands
[res_ands
? 2 : 3];
126 BOOST_CHECK(sizeof(array_ands
) / sizeof(char) == 3);
128 // We avoid checking the tribool::operator safe_bool(),
129 // because GCC-4.8 fails to evaluate it at compile-time.
130 // Clang compiles well.
132 // constexpr bool res_safe_bool = tribool(true); // false
133 // constexpr tribool xxx = (tribool(true) || tribool(indeterminate));
134 // static_assert(xxx, "Must be true!");
137 std::cout
<< "no errors detected\n";