diff options
Diffstat (limited to 'src/utils/optional_bool.hpp')
-rw-r--r-- | src/utils/optional_bool.hpp | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/src/utils/optional_bool.hpp b/src/utils/optional_bool.hpp index c652ed3..867aca2 100644 --- a/src/utils/optional_bool.hpp +++ b/src/utils/optional_bool.hpp @@ -1,21 +1,37 @@ #pragma once -#include <optional> - #include <string> -namespace std -{ -inline -std::string to_string(const std::optional<bool> b) +struct OptionalBool { - if (!b) - return "unset"; - else if (*b) - return "true"; - else - return "false"; -} -} - -std::ostream& operator<<(std::ostream& os, const std::optional<bool>& o); + OptionalBool() = default; + + OptionalBool(bool value): + is_set(true), value(value) {} + + void set_value(bool value) + { + this->is_set = true; + this->value = value; + } + + void unset() + { + this->is_set = false; + } + + std::string to_string() const + { + if (this->is_set == false) + return "unset"; + else if (this->value) + return "true"; + else + return "false"; + } + + bool is_set{false}; + bool value{false}; +}; + +std::ostream& operator<<(std::ostream& os, const OptionalBool& o); |