summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2018-03-16 00:53:47 +0100
committerlouiz’ <louiz@louiz.org>2018-03-16 01:13:50 +0100
commitba879a882e031d7b8503f78fe41d1210000c96ca (patch)
treee5e4f8055e73437318a36bddebd1c6d426fdce8e /src/utils
parent3f088e7b3a1467a88e7c5ff9fb60dc4609d2bfa3 (diff)
downloadbiboumi-ba879a882e031d7b8503f78fe41d1210000c96ca.tar.gz
biboumi-ba879a882e031d7b8503f78fe41d1210000c96ca.tar.bz2
biboumi-ba879a882e031d7b8503f78fe41d1210000c96ca.tar.xz
biboumi-ba879a882e031d7b8503f78fe41d1210000c96ca.zip
Use std::optional<bool> instead of OptionalBool
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/optional_bool.cpp4
-rw-r--r--src/utils/optional_bool.hpp48
2 files changed, 18 insertions, 34 deletions
diff --git a/src/utils/optional_bool.cpp b/src/utils/optional_bool.cpp
index 56fdca2..1d1c375 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 OptionalBool& o)
+std::ostream& operator<<(std::ostream& os, const std::optional<bool>& o)
{
- os << o.to_string();
+ os << std::to_string(o);
return os;
}
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);