2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
22 //////////////////////////////////////////////////////////////////////
25 * Represents definitely yes, definitely no, or maybe.
28 enum class TriBool
: uint8_t {
34 // Union represents "either", so values become Maybe unless both
35 // agree. The bit values of yes and no have been chosen to make this
37 inline TriBool
operator|(TriBool a
, TriBool b
) {
38 return static_cast<TriBool
>(
39 static_cast<std::underlying_type
<TriBool
>::type
>(a
) |
40 static_cast<std::underlying_type
<TriBool
>::type
>(b
)
44 // Intersection represents sequentiality, so Yes wins over everything,
45 // and No yields to anything else.
46 inline TriBool
operator&(TriBool a
, TriBool b
) {
47 if (a
== TriBool::No
) return b
;
48 if (a
== TriBool::Yes
) return a
;
49 if (b
== TriBool::Yes
) return b
;
53 inline TriBool
& operator|=(TriBool
& a
, TriBool b
) {
58 inline TriBool
& operator&=(TriBool
& a
, TriBool b
) {
63 inline TriBool
yesOrNo(bool b
) { return b
? TriBool::Yes
: TriBool::No
; }
64 inline TriBool
yesOrMaybe(bool b
) { return b
? TriBool::Yes
: TriBool::Maybe
; }
65 inline TriBool
maybeOrNo(bool b
) { return b
? TriBool::Maybe
: TriBool::No
; }
67 inline const char* show(TriBool b
) {
68 if (b
== TriBool::Yes
) return "yes";
69 if (b
== TriBool::No
) return "no";
73 //////////////////////////////////////////////////////////////////////