See N2136, Bool_set: multi-valued logic by Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion.
The implicit conversion to bool is slippery! I may use the new explicit conversion. This has been specialized in the language so that in contexts requiring a bool the conversion happens implicitly. Thus most objections should be eliminated.
Default constructor.
Constructor from bool.
Return true if states are equal.
Return true if this is empty.
Return true if this is indeterminate.
Return true if this is false or true (normal boolean).
Conversion to bool.
Bool set state.
41 _GLIBCXX_BEGIN_NAMESPACE_VERSION
59 constexpr bool_set() : _M_b(_S_false) { }
62 constexpr bool_set(
bool __t) : _M_b(_Bool_set_val(__t)) { }
65 bool contains(bool_set __b)
const
66 {
return this->is_singleton() && this->equals(__b); }
69 bool equals(bool_set __b)
const
70 {
return __b._M_b == _M_b; }
73 bool is_emptyset()
const
74 {
return _M_b == _S_empty; }
77 bool is_indeterminate()
const
78 {
return _M_b == _S_indet; }
81 bool is_singleton()
const
82 {
return _M_b == _S_false || _M_b == _S_true_; }
89 throw std::bad_cast();
94 static bool_set indeterminate()
102 static bool_set emptyset()
110 operator!(bool_set __b)
111 {
return __b._M_not(); }
114 operator^(bool_set __s, bool_set __t)
115 {
return __s._M_xor(__t); }
118 operator|(bool_set __s, bool_set __t)
119 {
return __s._M_or(__t); }
122 operator&(bool_set __s, bool_set __t)
123 {
return __s._M_and(__t); }
127 {
return __s._M_eq(__t); }
132 template<
typename CharT,
typename Traits>
133 friend std::basic_ostream<CharT, Traits>&
134 operator<<(std::basic_ostream<CharT, Traits>& __out, bool_set __b)
140 template<
typename CharT,
typename Traits>
141 friend std::basic_istream<CharT, Traits>&
142 operator>>(std::basic_istream<CharT, Traits>& __in, bool_set& __b)
146 if (__c >= _S_false && __c < _S_empty)
147 __b._M_b =
static_cast<_Bool_set_val
>(__c);
153 enum _Bool_set_val:
unsigned char
165 bool_set(_Bool_set_val __c) : _M_b(__c) { }
168 bool_set _M_not()
const
169 {
return _S_not[this->_M_b]; }
172 bool_set _M_xor(bool_set __b)
const
173 {
return _S_xor[this->_M_b][__b._M_b]; }
176 bool_set _M_or(bool_set __b)
const
177 {
return _S_or[this->_M_b][__b._M_b]; }
180 bool_set _M_and(bool_set __b)
const
181 {
return _S_and[this->_M_b][__b._M_b]; }
184 bool_set _M_eq(bool_set __b)
const
185 {
return _S_eq[this->_M_b][__b._M_b]; }
188 static _Bool_set_val _S_not[4];
191 static _Bool_set_val _S_xor[4][4];
194 static _Bool_set_val _S_or[4][4];
197 static _Bool_set_val _S_and[4][4];
200 static _Bool_set_val _S_eq[4][4];
206 contains(bool_set __s, bool_set __t)
207 {
return __s.contains(__t); }
210 equals(bool_set __s, bool_set __t)
211 {
return __s.equals(__t); }
214 is_emptyset(bool_set __b)
215 {
return __b.is_emptyset(); }
218 is_indeterminate(bool_set __b)
219 {
return __b.is_indeterminate(); }
222 is_singleton(bool_set __b)
223 {
return __b.is_singleton(); }
226 certainly(bool_set __b)
227 {
return ! __b.contains(
false); }
230 possibly(bool_set __b)
231 {
return __b.contains(
true); }
237 set_union(
bool __s, bool_set __t)
238 {
return bool_set(__s) | __t; }
241 set_union(bool_set __s,
bool __t)
242 {
return __s | bool_set(__t); }
245 set_union(bool_set __s, bool_set __t)
246 {
return __s | __t; }
249 set_intersection(
bool __s, bool_set __t)
250 {
return bool_set(__s) & __t; }
253 set_intersection(bool_set __s,
bool __t)
254 {
return __s & bool_set(__t); }
257 set_intersection(bool_set __s, bool_set __t)
258 {
return __s & __t; }
261 set_complement(bool_set __b)
268 operator^(
bool __s, bool_set __t)
269 {
return bool_set(__s) ^ __t; }
272 operator^(bool_set __s,
bool __t)
273 {
return __s ^ bool_set(__t); }
276 operator|(
bool __s, bool_set __t)
277 {
return bool_set(__s) | __t; }
280 operator|(bool_set __s,
bool __t)
281 {
return __s | bool_set(__t); }
284 operator&(
bool __s, bool_set __t)
285 {
return bool_set(__s) & __t; }
288 operator&(bool_set __s,
bool __t)
289 {
return __s & bool_set(__t); }
296 {
return bool_set(__s) == __t; }
300 {
return __s == bool_set(__t); }
304 {
return ! (__s == __t); }
308 {
return ! (__s == __t); }
312 {
return ! (__s == __t); }
314 _GLIBCXX_END_NAMESPACE_VERSION
bool operator==(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
#define bool
Definition: stdbool.h:33
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, basic_string< _CharT, _Traits, _Allocator > &__str)
Definition: string:1122
bool operator!=(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))