Go to the documentation of this file.
9 #ifndef EAGINE_TRIBOOL_HPP
10 #define EAGINE_TRIBOOL_HPP
14 enum class _tribool_value_t : unsigned char {
33 using _value_t = _tribool_value_t;
38 constexpr
explicit weakbool(_value_t value) noexcept
43 constexpr
explicit operator bool() const noexcept {
44 return _value != _value_t::_false;
49 return _value != _value_t::_true;
54 return _value == _value_t::_unknown;
63 using _value_t = _tribool_value_t;
64 _value_t _value{_value_t::_false};
68 constexpr
tribool() noexcept =
default;
72 : _value(value ? _value_t::_true : _value_t::_false) {}
76 : _value(_value_t::_unknown) {}
79 constexpr
tribool(
bool value,
bool is_unknown) noexcept
81 is_unknown ? _value_t::_unknown
82 : value ? _value_t::_true : _value_t::_false) {}
85 constexpr
explicit operator bool() const noexcept {
86 return _value == _value_t::_true;
91 return _value == _value_t::_false;
96 return _value == _value_t::_unknown;
105 constexpr
auto is(
bool value)
const noexcept ->
bool {
106 return _value == (value ? _value_t::_true : _value_t::_false);
116 return {a._value == b._value, (*a || *b)};
121 return {a._value != b._value, (*a || *b)};
139 #endif // EAGINE_TRIBOOL_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21
constexpr tribool(bool value, bool is_unknown) noexcept
Construction with separate true/false, known/unknown arguments.
Definition: tribool.hpp:79
constexpr static const indeterminate_t indeterminate
Constant representing unspecified tribool value.
Definition: tribool.hpp:24
Tri-state boolean value.
Definition: tribool.hpp:61
constexpr auto operator&&(tribool a, tribool b) noexcept
Tri-state boolean and operator.
Definition: tribool.hpp:126
constexpr auto operator!() const noexcept
Returns true, if the stored value is false.
Definition: tribool.hpp:90
Type of the indeterminate constant assignable to tribool.
Definition: tribool.hpp:21
Weak tri-state boolean value.
Definition: tribool.hpp:31
constexpr auto is(indeterminate_t) const noexcept
@ brief Checks if the stored value is indeterminate.
Definition: tribool.hpp:53
constexpr auto operator~() const noexcept -> weakbool
Converts this value to weakbool.
Definition: tribool.hpp:100
constexpr tribool(indeterminate_t) noexcept
Constructions from indeterminate value.
Definition: tribool.hpp:75
constexpr auto operator||(tribool a, tribool b) noexcept
Tri-state boolean or operator.
Definition: tribool.hpp:132
constexpr auto operator!() const noexcept
Returns true, if the stored value is not true.
Definition: tribool.hpp:48
constexpr tribool(bool value) noexcept
Constructions from boolean value.
Definition: tribool.hpp:71
constexpr tribool() noexcept=default
Default constructor.
constexpr auto is(bool value) const noexcept -> bool
Returns true if the stored value is known and equal to value.
Definition: tribool.hpp:105
constexpr auto is(indeterminate_t) const noexcept -> bool
Returns true if the stored value is indeterminate.
Definition: tribool.hpp:110
constexpr friend auto operator==(tribool a, tribool b) noexcept -> tribool
Equality comparison.
Definition: tribool.hpp:115
constexpr auto operator*() const noexcept -> bool
Returns true, if the stored value is indeterminate.
Definition: tribool.hpp:95
constexpr friend auto operator!=(tribool a, tribool b) noexcept -> tribool
Non-equality comparison.
Definition: tribool.hpp:120