From 5faedf45cc3da48720489b5131408b57d62151cd Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 29 Jun 2022 11:40:52 -0400 Subject: [PATCH] chore: Remove custom optional.h (no longer needed) Now windows builtin includes provide optional --- src/lib/md/Product.h | 4 +-- src/lib/md/cme/MDP3Utils.h | 2 +- src/lib/md/vendor/OnixsUtils.h | 2 +- src/lib/utils/optional.h | 60 ---------------------------------- src/lib/utils/parse_enum.h | 5 +-- 5 files changed, 7 insertions(+), 66 deletions(-) delete mode 100644 src/lib/utils/optional.h diff --git a/src/lib/md/Product.h b/src/lib/md/Product.h index 92a22dd8d..1702c1795 100644 --- a/src/lib/md/Product.h +++ b/src/lib/md/Product.h @@ -1,6 +1,6 @@ #pragma once #include "lib/domain_model/Security.pb.h" -#include "lib/utils/optional.h" +#include #include namespace bts { @@ -10,4 +10,4 @@ std::string product_to_string(const api::Product &); std::optional string_to_product(const std::string &); } // namespace api -} // namespace bts \ No newline at end of file +} // namespace bts diff --git a/src/lib/md/cme/MDP3Utils.h b/src/lib/md/cme/MDP3Utils.h index 17ffb43ce..87f1cc24a 100644 --- a/src/lib/md/cme/MDP3Utils.h +++ b/src/lib/md/cme/MDP3Utils.h @@ -1,7 +1,7 @@ #pragma once #include "lib/md/coconut2.h" -#include "lib/utils/optional.h" +#include #include #include #include diff --git a/src/lib/md/vendor/OnixsUtils.h b/src/lib/md/vendor/OnixsUtils.h index a760383cf..5b5fd39da 100644 --- a/src/lib/md/vendor/OnixsUtils.h +++ b/src/lib/md/vendor/OnixsUtils.h @@ -1,6 +1,6 @@ #pragma once #include "boost/filesystem.hpp" -#include "lib/utils/optional.h" +#include namespace bts { namespace md { diff --git a/src/lib/utils/optional.h b/src/lib/utils/optional.h deleted file mode 100644 index 1fc2e545a..000000000 --- a/src/lib/utils/optional.h +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once -// An incomplete version of std::optional which should work well enough on -// Windows until it catch up -#ifdef _WIN32 -#include -namespace std { -class bad_optional_access : exception {}; - -template class optional { - bool _has_value; - union { - T _value; - int _unused; - }; - - public: - optional(const T &value) : _has_value(true), _value(value) {} - optional(T &&value) : _has_value(true), _value(value) {} - optional() : _has_value(false) ~optional() { reset(); } - bool has_value() const { return _has_value; } - operator bool() { return b.has_value(); } - T &operator*() { - if (has_value()) { - return _value; - } else - throw std::bad_optional_access(); - } - const T &operator*() const { return **this; } - T &operator->() { return **this; } - const T &operator->() const { return **this; } - bool operator==(const std::optional &other) const { - if (!_has_value && !other.has_value()) - return true; - return _has_value == other._has_value && _value == other.value(); - } - bool operator!=(const std::optional &other) const { - return !(*this == other); - } - T &value() { return **this; } - const T &value() const { return **this; } - T value_or(T default_value) { - if (has_value()) - return _value; - else - return default_value; - } - void reset() { - if (has_value()) { - _value.~T(); - _has_value = false; - } - } - // This class is incomplete. Add methods as necessary -}; - -template constexpr optional nullopt = {}; -} // namespace std -#else -#include -#endif \ No newline at end of file diff --git a/src/lib/utils/parse_enum.h b/src/lib/utils/parse_enum.h index 6c4ca6d89..9ec1c5f7c 100644 --- a/src/lib/utils/parse_enum.h +++ b/src/lib/utils/parse_enum.h @@ -1,7 +1,8 @@ #pragma once -#include "lib/utils/optional.h" +#include #include + namespace bts { inline std::string uppercase_copy(const std::string &cs) { @@ -24,4 +25,4 @@ parse_enum(const std::string &value, const std::string &prefix, T2 parse) { return std::nullopt; } } -} // namespace bts \ No newline at end of file +} // namespace bts