diff options
author | louiz’ <louiz@louiz.org> | 2018-03-17 17:33:17 +0100 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2018-03-17 17:34:00 +0100 |
commit | f8a1048ffeec6322c1e64a0eda7636a977669898 (patch) | |
tree | e5e4f8055e73437318a36bddebd1c6d426fdce8e /src/utils/optional_bool.hpp | |
parent | b956b9d1aa27ac71432839e286f3db0a19aebf6b (diff) | |
download | biboumi-f8a1048ffeec6322c1e64a0eda7636a977669898.tar.gz biboumi-f8a1048ffeec6322c1e64a0eda7636a977669898.tar.bz2 biboumi-f8a1048ffeec6322c1e64a0eda7636a977669898.tar.xz biboumi-f8a1048ffeec6322c1e64a0eda7636a977669898.zip |
Re-apply "Use std::optional<bool> instead of OptionalBool"
This reverts commit 03714c6cebf90dc7db8e3997a18cdd19e039c667.
Diffstat (limited to 'src/utils/optional_bool.hpp')
-rw-r--r-- | src/utils/optional_bool.hpp | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/src/utils/optional_bool.hpp b/src/utils/optional_bool.hpp index 867aca2..c652ed3 100644 --- a/src/utils/optional_bool.hpp +++ b/src/utils/optional_bool.hpp @@ -1,37 +1,21 @@ #pragma once +#include <optional> + #include <string> -struct OptionalBool +namespace std { - 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); +inline +std::string to_string(const std::optional<bool> b) +{ + if (!b) + return "unset"; + else if (*b) + return "true"; + else + return "false"; +} +} + +std::ostream& operator<<(std::ostream& os, const std::optional<bool>& o); |