From 9b501276fb1a85df856f308ef86e684e0e78abbc Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 29 Aug 2014 10:56:03 +0200 Subject: [PATCH] upgrade variant dependency --- ThirdParty/variant/optional.hpp | 78 +++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 ThirdParty/variant/optional.hpp diff --git a/ThirdParty/variant/optional.hpp b/ThirdParty/variant/optional.hpp new file mode 100644 index 000000000..7c328da34 --- /dev/null +++ b/ThirdParty/variant/optional.hpp @@ -0,0 +1,78 @@ +#ifndef MAPBOX_UTIL_OPTIONAL_HPP +#define MAPBOX_UTIL_OPTIONAL_HPP + +#include + +#include "variant.hpp" + +namespace mapbox +{ +namespace util +{ + +template class optional +{ + static_assert(!std::is_reference::value, "optional doesn't support references"); + + struct none_type + { + }; + + variant 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; } + + optional &operator=(optional other) + { // note: argument passed by value! + if (this != &other) + { + swap(other); + } + return *this; + } + + explicit operator bool() const noexcept { return variant_.template is(); } + + T const &get() const { return variant_.template get(); } + T &get() { return variant_.template get(); } + + 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 void emplace(Args &&... args) + { + variant_ = T{std::forward(args)...}; + } + + void reset() { variant_ = none_type{}; } +}; +} +} + +#endif