Use std::optional<bool> instead of OptionalBool

This commit is contained in:
louiz’
2018-03-16 01:13:50 +01:00
parent 3f088e7b3a
commit ba879a882e
8 changed files with 41 additions and 58 deletions
+2 -2
View File
@@ -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;
}
+15 -31
View File
@@ -1,37 +1,21 @@
#pragma once
#include <optional>
#include <string>
struct OptionalBool
namespace std
{
OptionalBool() = default;
inline
std::string to_string(const std::optional<bool> b)
{
if (!b)
return "unset";
else if (*b)
return "true";
else
return "false";
}
}
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);
std::ostream& operator<<(std::ostream& os, const std::optional<bool>& o);