comparison DEPENDENCIES/generic/include/boost/logic/tribool.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
12 12
13 #include <boost/logic/tribool_fwd.hpp> 13 #include <boost/logic/tribool_fwd.hpp>
14 #include <boost/config.hpp> 14 #include <boost/config.hpp>
15 #include <boost/detail/workaround.hpp> 15 #include <boost/detail/workaround.hpp>
16 16
17 #if BOOST_WORKAROUND(_MSC_VER, >= 1200) 17 #ifdef BOOST_HAS_PRAGMA_ONCE
18 # pragma once 18 # pragma once
19 #endif 19 #endif
20 20
21 namespace boost { namespace logic { 21 namespace boost { namespace logic {
22 22
57 * macro \c BOOST_TRIBOOL_THIRD_STATE. 57 * macro \c BOOST_TRIBOOL_THIRD_STATE.
58 * 58 *
59 * \returns <tt>x.value == tribool::indeterminate_value</tt> 59 * \returns <tt>x.value == tribool::indeterminate_value</tt>
60 * \throws nothrow 60 * \throws nothrow
61 */ 61 */
62 inline bool 62 BOOST_CONSTEXPR inline bool
63 indeterminate(tribool x, 63 indeterminate(tribool x,
64 detail::indeterminate_t dummy = detail::indeterminate_t()); 64 detail::indeterminate_t dummy = detail::indeterminate_t()) BOOST_NOEXCEPT;
65 65
66 /** 66 /**
67 * \brief A 3-state boolean type. 67 * \brief A 3-state boolean type.
68 * 68 *
69 * 3-state boolean values are either true, false, or 69 * 3-state boolean values are either true, false, or
83 /** 83 /**
84 * Construct a new 3-state boolean value with the value 'false'. 84 * Construct a new 3-state boolean value with the value 'false'.
85 * 85 *
86 * \throws nothrow 86 * \throws nothrow
87 */ 87 */
88 tribool() : value(false_value) {} 88 BOOST_CONSTEXPR tribool() BOOST_NOEXCEPT : value(false_value) {}
89 89
90 /** 90 /**
91 * Construct a new 3-state boolean value with the given boolean 91 * Construct a new 3-state boolean value with the given boolean
92 * value, which may be \c true or \c false. 92 * value, which may be \c true or \c false.
93 * 93 *
94 * \throws nothrow 94 * \throws nothrow
95 */ 95 */
96 tribool(bool initial_value) : value(initial_value? true_value : false_value) {} 96 BOOST_CONSTEXPR tribool(bool initial_value) BOOST_NOEXCEPT : value(initial_value? true_value : false_value) {}
97 97
98 /** 98 /**
99 * Construct a new 3-state boolean value with an indeterminate value. 99 * Construct a new 3-state boolean value with an indeterminate value.
100 * 100 *
101 * \throws nothrow 101 * \throws nothrow
102 */ 102 */
103 tribool(indeterminate_keyword_t) : value(indeterminate_value) {} 103 BOOST_CONSTEXPR tribool(indeterminate_keyword_t) BOOST_NOEXCEPT : value(indeterminate_value) {}
104 104
105 /** 105 /**
106 * Use a 3-state boolean in a boolean context. Will evaluate true in a 106 * Use a 3-state boolean in a boolean context. Will evaluate true in a
107 * boolean context only when the 3-state boolean is definitely true. 107 * boolean context only when the 3-state boolean is definitely true.
108 * 108 *
109 * \returns true if the 3-state boolean is true, false otherwise 109 * \returns true if the 3-state boolean is true, false otherwise
110 * \throws nothrow 110 * \throws nothrow
111 */ 111 */
112 operator safe_bool() const 112 BOOST_CONSTEXPR operator safe_bool() const BOOST_NOEXCEPT
113 { 113 {
114 return value == true_value? &dummy::nonnull : 0; 114 return value == true_value? &dummy::nonnull : 0;
115 } 115 }
116 116
117 /** 117 /**
121 enum value_t { false_value, true_value, indeterminate_value } value; 121 enum value_t { false_value, true_value, indeterminate_value } value;
122 }; 122 };
123 123
124 // Check if the given tribool has an indeterminate value. Also doubles as a 124 // Check if the given tribool has an indeterminate value. Also doubles as a
125 // keyword for the 'indeterminate' value 125 // keyword for the 'indeterminate' value
126 inline bool indeterminate(tribool x, detail::indeterminate_t) 126 BOOST_CONSTEXPR inline bool indeterminate(tribool x, detail::indeterminate_t) BOOST_NOEXCEPT
127 { 127 {
128 return x.value == tribool::indeterminate_value; 128 return x.value == tribool::indeterminate_value;
129 } 129 }
130 130
131 /** @defgroup logical Logical operations 131 /** @defgroup logical Logical operations
154 * <td><center>indeterminate</center></td> 154 * <td><center>indeterminate</center></td>
155 * </tr> 155 * </tr>
156 * </table> 156 * </table>
157 * \throws nothrow 157 * \throws nothrow
158 */ 158 */
159 inline tribool operator!(tribool x) 159 BOOST_CONSTEXPR inline tribool operator!(tribool x) BOOST_NOEXCEPT
160 { 160 {
161 return x.value == tribool::false_value? tribool(true) 161 return x.value == tribool::false_value? tribool(true)
162 :x.value == tribool::true_value? tribool(false) 162 :x.value == tribool::true_value? tribool(false)
163 :tribool(indeterminate); 163 :tribool(indeterminate);
164 } 164 }
194 * <td><center>indeterminate</center></td> 194 * <td><center>indeterminate</center></td>
195 * </tr> 195 * </tr>
196 * </table> 196 * </table>
197 * \throws nothrow 197 * \throws nothrow
198 */ 198 */
199 inline tribool operator&&(tribool x, tribool y) 199 BOOST_CONSTEXPR inline tribool operator&&(tribool x, tribool y) BOOST_NOEXCEPT
200 { 200 {
201 if (static_cast<bool>(!x) || static_cast<bool>(!y)) 201 return (static_cast<bool>(!x) || static_cast<bool>(!y))
202 return false; 202 ? tribool(false)
203 else if (static_cast<bool>(x) && static_cast<bool>(y)) 203 : ((static_cast<bool>(x) && static_cast<bool>(y)) ? tribool(true) : indeterminate)
204 return true; 204 ;
205 else 205 }
206 return indeterminate; 206
207 } 207 /**
208 208 * \overload
209 /** 209 */
210 * \overload 210 BOOST_CONSTEXPR inline tribool operator&&(tribool x, bool y) BOOST_NOEXCEPT
211 */
212 inline tribool operator&&(tribool x, bool y)
213 { return y? x : tribool(false); } 211 { return y? x : tribool(false); }
214 212
215 /** 213 /**
216 * \overload 214 * \overload
217 */ 215 */
218 inline tribool operator&&(bool x, tribool y) 216 BOOST_CONSTEXPR inline tribool operator&&(bool x, tribool y) BOOST_NOEXCEPT
219 { return x? y : tribool(false); } 217 { return x? y : tribool(false); }
220 218
221 /** 219 /**
222 * \overload 220 * \overload
223 */ 221 */
224 inline tribool operator&&(indeterminate_keyword_t, tribool x) 222 BOOST_CONSTEXPR inline tribool operator&&(indeterminate_keyword_t, tribool x) BOOST_NOEXCEPT
225 { return !x? tribool(false) : tribool(indeterminate); } 223 { return !x? tribool(false) : tribool(indeterminate); }
226 224
227 /** 225 /**
228 * \overload 226 * \overload
229 */ 227 */
230 inline tribool operator&&(tribool x, indeterminate_keyword_t) 228 BOOST_CONSTEXPR inline tribool operator&&(tribool x, indeterminate_keyword_t) BOOST_NOEXCEPT
231 { return !x? tribool(false) : tribool(indeterminate); } 229 { return !x? tribool(false) : tribool(indeterminate); }
232 230
233 /** 231 /**
234 * \brief Computes the logical disjunction of two tribools 232 * \brief Computes the logical disjunction of two tribools
235 * 233 *
261 * <td><center>indeterminate</center></td> 259 * <td><center>indeterminate</center></td>
262 * </tr> 260 * </tr>
263 * </table> 261 * </table>
264 * \throws nothrow 262 * \throws nothrow
265 */ 263 */
266 inline tribool operator||(tribool x, tribool y) 264 BOOST_CONSTEXPR inline tribool operator||(tribool x, tribool y) BOOST_NOEXCEPT
267 { 265 {
268 if (static_cast<bool>(!x) && static_cast<bool>(!y)) 266 return (static_cast<bool>(!x) && static_cast<bool>(!y))
269 return false; 267 ? tribool(false)
270 else if (static_cast<bool>(x) || static_cast<bool>(y)) 268 : ((static_cast<bool>(x) || static_cast<bool>(y)) ? tribool(true) : tribool(indeterminate))
271 return true; 269 ;
272 else 270 }
273 return indeterminate; 271
274 } 272 /**
275 273 * \overload
276 /** 274 */
277 * \overload 275 BOOST_CONSTEXPR inline tribool operator||(tribool x, bool y) BOOST_NOEXCEPT
278 */
279 inline tribool operator||(tribool x, bool y)
280 { return y? tribool(true) : x; } 276 { return y? tribool(true) : x; }
281 277
282 /** 278 /**
283 * \overload 279 * \overload
284 */ 280 */
285 inline tribool operator||(bool x, tribool y) 281 BOOST_CONSTEXPR inline tribool operator||(bool x, tribool y) BOOST_NOEXCEPT
286 { return x? tribool(true) : y; } 282 { return x? tribool(true) : y; }
287 283
288 /** 284 /**
289 * \overload 285 * \overload
290 */ 286 */
291 inline tribool operator||(indeterminate_keyword_t, tribool x) 287 BOOST_CONSTEXPR inline tribool operator||(indeterminate_keyword_t, tribool x) BOOST_NOEXCEPT
292 { return x? tribool(true) : tribool(indeterminate); } 288 { return x? tribool(true) : tribool(indeterminate); }
293 289
294 /** 290 /**
295 * \overload 291 * \overload
296 */ 292 */
297 inline tribool operator||(tribool x, indeterminate_keyword_t) 293 BOOST_CONSTEXPR inline tribool operator||(tribool x, indeterminate_keyword_t) BOOST_NOEXCEPT
298 { return x? tribool(true) : tribool(indeterminate); } 294 { return x? tribool(true) : tribool(indeterminate); }
299 //@} 295 //@}
300 296
301 /** 297 /**
302 * \brief Compare tribools for equality 298 * \brief Compare tribools for equality
329 * <td><center>indeterminate</center></td> 325 * <td><center>indeterminate</center></td>
330 * </tr> 326 * </tr>
331 * </table> 327 * </table>
332 * \throws nothrow 328 * \throws nothrow
333 */ 329 */
334 inline tribool operator==(tribool x, tribool y) 330 BOOST_CONSTEXPR inline tribool operator==(tribool x, tribool y) BOOST_NOEXCEPT
335 { 331 {
336 if (indeterminate(x) || indeterminate(y)) 332 return (indeterminate(x) || indeterminate(y))
337 return indeterminate; 333 ? indeterminate
338 else 334 : ((x && y) || (!x && !y))
339 return (x && y) || (!x && !y); 335 ;
340 } 336 }
341 337
342 /** 338 /**
343 * \overload 339 * \overload
344 */ 340 */
345 inline tribool operator==(tribool x, bool y) { return x == tribool(y); } 341 BOOST_CONSTEXPR inline tribool operator==(tribool x, bool y) BOOST_NOEXCEPT { return x == tribool(y); }
346 342
347 /** 343 /**
348 * \overload 344 * \overload
349 */ 345 */
350 inline tribool operator==(bool x, tribool y) { return tribool(x) == y; } 346 BOOST_CONSTEXPR inline tribool operator==(bool x, tribool y) BOOST_NOEXCEPT { return tribool(x) == y; }
351 347
352 /** 348 /**
353 * \overload 349 * \overload
354 */ 350 */
355 inline tribool operator==(indeterminate_keyword_t, tribool x) 351 BOOST_CONSTEXPR inline tribool operator==(indeterminate_keyword_t, tribool x) BOOST_NOEXCEPT
356 { return tribool(indeterminate) == x; } 352 { return tribool(indeterminate) == x; }
357 353
358 /** 354 /**
359 * \overload 355 * \overload
360 */ 356 */
361 inline tribool operator==(tribool x, indeterminate_keyword_t) 357 BOOST_CONSTEXPR inline tribool operator==(tribool x, indeterminate_keyword_t) BOOST_NOEXCEPT
362 { return tribool(indeterminate) == x; } 358 { return tribool(indeterminate) == x; }
363 359
364 /** 360 /**
365 * \brief Compare tribools for inequality 361 * \brief Compare tribools for inequality
366 * 362 *
392 * <td><center>indeterminate</center></td> 388 * <td><center>indeterminate</center></td>
393 * </tr> 389 * </tr>
394 * </table> 390 * </table>
395 * \throws nothrow 391 * \throws nothrow
396 */ 392 */
397 inline tribool operator!=(tribool x, tribool y) 393 BOOST_CONSTEXPR inline tribool operator!=(tribool x, tribool y) BOOST_NOEXCEPT
398 { 394 {
399 if (indeterminate(x) || indeterminate(y)) 395 return (indeterminate(x) || indeterminate(y))
400 return indeterminate; 396 ? indeterminate
401 else 397 : !((x && y) || (!x && !y))
402 return !((x && y) || (!x && !y)); 398 ;
403 } 399 }
404 400
405 /** 401 /**
406 * \overload 402 * \overload
407 */ 403 */
408 inline tribool operator!=(tribool x, bool y) { return x != tribool(y); } 404 BOOST_CONSTEXPR inline tribool operator!=(tribool x, bool y) BOOST_NOEXCEPT { return x != tribool(y); }
409 405
410 /** 406 /**
411 * \overload 407 * \overload
412 */ 408 */
413 inline tribool operator!=(bool x, tribool y) { return tribool(x) != y; } 409 BOOST_CONSTEXPR inline tribool operator!=(bool x, tribool y) BOOST_NOEXCEPT { return tribool(x) != y; }
414 410
415 /** 411 /**
416 * \overload 412 * \overload
417 */ 413 */
418 inline tribool operator!=(indeterminate_keyword_t, tribool x) 414 BOOST_CONSTEXPR inline tribool operator!=(indeterminate_keyword_t, tribool x) BOOST_NOEXCEPT
419 { return tribool(indeterminate) != x; } 415 { return tribool(indeterminate) != x; }
420 416
421 /** 417 /**
422 * \overload 418 * \overload
423 */ 419 */
424 inline tribool operator!=(tribool x, indeterminate_keyword_t) 420 BOOST_CONSTEXPR inline tribool operator!=(tribool x, indeterminate_keyword_t) BOOST_NOEXCEPT
425 { return x != tribool(indeterminate); } 421 { return x != tribool(indeterminate); }
426 422
427 } } // end namespace boost::logic 423 } } // end namespace boost::logic
428 424
429 // Pull tribool and indeterminate into namespace "boost" 425 // Pull tribool and indeterminate into namespace "boost"