diff options
author | louiz’ <louiz@louiz.org> | 2018-03-17 17:28:47 +0100 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2018-03-17 17:28:47 +0100 |
commit | 03714c6cebf90dc7db8e3997a18cdd19e039c667 (patch) | |
tree | c7f32136db1a40492f18cbd635a1bab761d14ced /src/utils | |
parent | d0e3c71b91f1a1c1780158789fd42b8ac7209495 (diff) | |
download | biboumi-03714c6cebf90dc7db8e3997a18cdd19e039c667.tar.gz biboumi-03714c6cebf90dc7db8e3997a18cdd19e039c667.tar.bz2 biboumi-03714c6cebf90dc7db8e3997a18cdd19e039c667.tar.xz biboumi-03714c6cebf90dc7db8e3997a18cdd19e039c667.zip |
Revert "Use std::optional<bool> instead of OptionalBool"
This reverts commit ba879a882e031d7b8503f78fe41d1210000c96ca.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/optional_bool.cpp | 4 | ||||
-rw-r--r-- | src/utils/optional_bool.hpp | 48 |
2 files changed, 34 insertions, 18 deletions
diff --git a/src/utils/optional_bool.cpp b/src/utils/optional_bool.cpp index 1d1c375..56fdca2 100644 --- a/src/utils/optional_bool.cpp +++ b/src/utils/optional_bool.cpp @@ -1,8 +1,8 @@ #include <utils/optional_bool.hpp> -std::ostream& operator<<(std::ostream& os, const std::optional<bool>& o) +std::ostream& operator<<(std::ostream& os, const OptionalBool& o) { - os << std::to_string(o); + os << o.to_string(); return os; } 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); |