]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/logic/test/tribool_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / 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)
5
6 #include <boost/logic/tribool.hpp>
7 #include <boost/test/minimal.hpp>
8 #include <iostream>
9
10 int test_main(int, char*[])
11 {
12 using namespace boost::logic;
13
14 tribool x; // false
15 tribool y(true); // true
16 tribool z(indeterminate); // indeterminate
17
18 BOOST_CHECK(!x);
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));
27 BOOST_CHECK(x == 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);
33
34 BOOST_CHECK(y);
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));
43 BOOST_CHECK(y == y);
44 BOOST_CHECK(!(y != y));
45
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));
57
58 BOOST_CHECK(!(x == y));
59 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));
64
65 BOOST_CHECK(!(x && y));
66 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));
72 BOOST_CHECK(y || z);
73
74 BOOST_CHECK(indeterminate(y && indeterminate));
75 BOOST_CHECK(indeterminate(indeterminate && y));
76 BOOST_CHECK(!(x && indeterminate));
77 BOOST_CHECK(!(indeterminate && x));
78
79 BOOST_CHECK(indeterminate || y);
80 BOOST_CHECK(y || indeterminate);
81 BOOST_CHECK(indeterminate(x || indeterminate));
82 BOOST_CHECK(indeterminate(indeterminate || x));
83
84 // Test the if (z) ... else (!z) ... else ... idiom
85 if (z) {
86 BOOST_CHECK(false);
87 }
88 else if (!z) {
89 BOOST_CHECK(false);
90 }
91 else {
92 BOOST_CHECK(true);
93 }
94
95 z = true;
96 if (z) {
97 BOOST_CHECK(true);
98 }
99 else if (!z) {
100 BOOST_CHECK(false);
101 }
102 else {
103 BOOST_CHECK(false);
104 }
105
106 z = false;
107 if (z) {
108 BOOST_CHECK(false);
109 }
110 else if (!z) {
111 BOOST_CHECK(true);
112 }
113 else {
114 BOOST_CHECK(false);
115 }
116
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);
122
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);
127
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.
131 //
132 // constexpr bool res_safe_bool = tribool(true); // false
133 // constexpr tribool xxx = (tribool(true) || tribool(indeterminate));
134 // static_assert(xxx, "Must be true!");
135 #endif
136
137 std::cout << "no errors detected\n";
138 return 0;
139 }