chore: Remove custom optional.h (no longer needed)

Now windows builtin includes provide optional
This commit is contained in:
John Colvin committed 2022-07-01 13:18:05 -05:00
1 parent aad6d1b5e3
commit 5faedf45cc
5 files changed
+7 -66

No files matched your search

+2 -2
View File
@@ -1,6 +1,6 @@
#pragma once
#include "lib/domain_model/Security.pb.h"
#include "lib/utils/optional.h"
#include <optional>
#include <string>
namespace bts {
@@ -10,4 +10,4 @@ std::string product_to_string(const api::Product &);
std::optional<api::Product> string_to_product(const std::string &);
} // namespace api
} // namespace bts
} // namespace bts
+1 -1
View File
@@ -1,7 +1,7 @@
#pragma once
#include "lib/md/coconut2.h"
#include "lib/utils/optional.h"
#include <optional>
#include <set>
#include <string>
#include <vector>
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once
#include "boost/filesystem.hpp"
#include "lib/utils/optional.h"
#include <optional>
namespace bts {
namespace md {
-60
View File
@@ -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 <exception>
namespace std {
class bad_optional_access : exception {};
template <class T> 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<T> &other) const {
if (!_has_value && !other.has_value())
return true;
return _has_value == other._has_value && _value == other.value();
}
bool operator!=(const std::optional<T> &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 <class T> constexpr optional<T> nullopt = {};
} // namespace std
#else
#include <optional>
#endif
+3 -2
View File
@@ -1,7 +1,8 @@
#pragma once
#include "lib/utils/optional.h"
#include <optional>
#include <string>
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
} // namespace bts