|
(Note that these are not member functions.)
|
constexpr tribool | operator&& (const tribool &lhs, const tribool &rhs) noexcept |
| Computes the logical and of two tribool. More...
|
|
constexpr tribool | operator|| (const tribool &lhs, const tribool &rhs) noexcept |
| Computes the logical or of two tribool. More...
|
|
template<typename CharT > |
constexpr const CharT * | get_default_indeterminate_name () noexcept |
| Returns the default indeterminate name. More...
|
|
template<typename CharT , typename Traits > |
auto | operator<< (std::basic_ostream< CharT, Traits > &out, const tribool &tri) -> decltype(out) |
| Outputs the value of the tribool to the stream provided. More...
|
|
template<typename CharT , typename Traits > |
auto | operator>> (std::basic_istream< CharT, Traits > &in, tribool &tri) -> decltype(in) |
| Reads a tribool value from an input stream. More...
|
|
Implements Kleene's logic for three-state booleans. This class should be preferred to gears::utility::maybe<bool>
as it implements true three-state logic. The three states for the boolean are true
, false
, and indeterminate
. So for example all three are valid:
namespace util = gears::utility;
util::tribool x = true;
x = false;
The input and output operators are supported by default. In order to disable it, you have to define the macro GEARS_NO_IOSTREAM
. The input/output operators behave similarly to bool
values, except indeterminate
can be read or output as 2. When std::boolalpha
is active, they can be read and written in the same similar manner except the default string would be "indeterminate". For example:
namespace util = gears::utility;
std::cout << std::boolalpha << x << '\n';
Output:
indeterminate
You can change the indeterminate
value through instantiating a value of type indeterminate_t
. Likewise, you can change the default string read or written through the use of the indeterminate_name
facet. For example:
namespace util = gears::utility;
constexpr util::indeterminate_t null{};
util::tribool x = null;
std::locale myloc(std::cout.getloc(), new util::indeterminate_name<char>("null"));
std::cout.imbue(myloc);
std::cout << std::boolalpha << x << '\n';
Output:
null
Definition at line 99 of file tribool.hpp.
template<typename CharT , typename Traits >
auto operator<< |
( |
std::basic_ostream< CharT, Traits > & |
out, |
|
|
const tribool & |
tri |
|
) |
| -> decltype(out) |
|
related |
Outputs the value of the tribool to the stream provided.
The value written when std::boolalpha
is not active is as follows:
internal value | output |
false | 0 |
true | 1 |
indeterminate | 2 |
If std::boolalpha
is written then the name written to depends on the facet provided. The true
and false
values are provided by the std::numpunct
functions that implement do_truename
and do_falsename
. The indeterminate value is provided by the indeterminate_name
facet.
Assuming everything is defaulted, the values written are as follows:
internal value | output |
false | "false" |
true | "true" |
indeterminate | "indeterminate" |
This operator overload is only available if GEARS_NO_IOSTREAM
is not defined.
- Parameters
-
out | Output stream to write to. |
tri | Tribool to read from. |
- Returns
- The output stream.
Definition at line 381 of file tribool.hpp.
template<typename CharT , typename Traits >
auto operator>> |
( |
std::basic_istream< CharT, Traits > & |
in, |
|
|
tribool & |
tri |
|
) |
| -> decltype(in) |
|
related |
Reads a tribool value from an input stream. This function works similarly to the output stream except inverted. That is, if std::boolalpha
is not active, then the values of 0, 1, and 2 will set the tribool appropriately otherwise failure will be set.
If std::boolalpha
is set then the string is read from the appropriate facets. Which are std::numpunct
for true
and false
and indeterminate_name
for the indeterminate value.
This operator overload is only available if GEARS_NO_IOSTREAM
is not defined.
- Parameters
-
in | The input stream to read from. |
tri | The tribool to place the value to. |
- Returns
- The input stream.
Definition at line 425 of file tribool.hpp.