aboutsummaryrefslogtreecommitdiff
path: root/third-party/mapbox/optional.hpp
diff options
context:
space:
mode:
authorJames Ward <james.ward@arm.com>2020-09-25 11:43:21 +0100
committerJames Ward <james.ward@arm.com>2020-09-30 08:41:31 +0000
commit22a4e1539aca7d39d7abc932f0a4d0b27beedf80 (patch)
tree95152943571413af5a3b550ac391bb17f258feef /third-party/mapbox/optional.hpp
parentba3ef18cb6117c49fcdbf177dce5991d6d679cbc (diff)
downloadarmnn-22a4e1539aca7d39d7abc932f0a4d0b27beedf80.tar.gz
IVGCVSW-4519 Remove Boost Variant and apply_visitor variant
* add mapbox/variant third party package Signed-off-by: James Ward <james.ward@arm.com> Change-Id: I181302780edd9dace40f158a11327316a12ce69a
Diffstat (limited to 'third-party/mapbox/optional.hpp')
-rw-r--r--third-party/mapbox/optional.hpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/third-party/mapbox/optional.hpp b/third-party/mapbox/optional.hpp
new file mode 100644
index 0000000000..d84705c1ac
--- /dev/null
+++ b/third-party/mapbox/optional.hpp
@@ -0,0 +1,74 @@
+#ifndef MAPBOX_UTIL_OPTIONAL_HPP
+#define MAPBOX_UTIL_OPTIONAL_HPP
+
+#pragma message("This implementation of optional is deprecated. See https://github.com/mapbox/variant/issues/64.")
+
+#include <type_traits>
+#include <utility>
+
+#include <mapbox/variant.hpp>
+
+namespace mapbox {
+namespace util {
+
+template <typename T>
+class optional
+{
+ static_assert(!std::is_reference<T>::value, "optional doesn't support references");
+
+ struct none_type
+ {
+ };
+
+ variant<none_type, T> variant_;
+
+public:
+ optional() = default;
+
+ optional(optional const& rhs)
+ {
+ if (this != &rhs)
+ { // protect against invalid self-assignment
+ variant_ = rhs.variant_;
+ }
+ }
+
+ optional(T const& v) { variant_ = v; }
+
+ explicit operator bool() const noexcept { return variant_.template is<T>(); }
+
+ T const& get() const { return variant_.template get<T>(); }
+ T& get() { return variant_.template get<T>(); }
+
+ T const& operator*() const { return this->get(); }
+ T operator*() { return this->get(); }
+
+ optional& operator=(T const& v)
+ {
+ variant_ = v;
+ return *this;
+ }
+
+ optional& operator=(optional const& rhs)
+ {
+ if (this != &rhs)
+ {
+ variant_ = rhs.variant_;
+ }
+ return *this;
+ }
+
+ template <typename... Args>
+ void emplace(Args&&... args)
+ {
+ variant_ = T{std::forward<Args>(args)...};
+ }
+
+ void reset() { variant_ = none_type{}; }
+
+}; // class optional
+
+} // namespace util
+} // namespace mapbox
+
+#endif // MAPBOX_UTIL_OPTIONAL_HPP