5 #ifndef TABLEAU_HYPER_OPTIONAL_HPP
6 #define TABLEAU_HYPER_OPTIONAL_HPP
8 #if !defined(__cplusplus) || (__cplusplus < 201703L)
9 #define hyper_use_own_optional
12 #ifdef hyper_use_own_optional
14 #include <type_traits>
20 #ifdef hyper_use_own_optional
22 #define CONSTEXPR_OPTIONAL const
24 #define CONSTEXPR_OPTIONAL constexpr
28 #ifndef hyper_use_own_optional
30 using optional = std::optional<T>;
31 using bad_optional_access = std::bad_optional_access;
35 using std::exception::exception;
43 alignas(T)
char data[
sizeof(T)];
64 typename = typename std::enable_if<!std::is_same<typename std::decay<U>::type,
optional<T>>::
value>::type>
74 template <typename Other>
75 bool operator==(const
optional<Other>& other) const noexcept {
76 return (exists == other.exists) && ((!exists) || (**
this == *other));
79 template <
typename Other>
88 explicit operator bool() const noexcept {
return exists; }
120 template <
typename U>
122 return bool(*
this) ? **this : static_cast<T>(std::forward<U>(default_value));
126 template <
typename U>
128 return bool(*
this) ? std::move(**
this) : static_cast<T>(std::forward<U>(default_value));
146 void reset() noexcept;
150 template <typename... Args>
155 template <typename... Args>
156 void create(Args&&... args);
159 T* ptr() noexcept {
return exists ? reinterpret_cast<T*>(data) : nullptr; }
161 const T* ptr() const noexcept {
return exists ? reinterpret_cast<const T*>(data) : nullptr; }
166 #include <hyperapi/impl/optional.impl.hpp>