diff --git a/deps/ox/src/ox/std/optional.hpp b/deps/ox/src/ox/std/optional.hpp index ab0cfc02..3110d5ab 100644 --- a/deps/ox/src/ox/std/optional.hpp +++ b/deps/ox/src/ox/std/optional.hpp @@ -51,14 +51,20 @@ class Optional { } } - template - constexpr U *get() noexcept { - return m_ptr; + constexpr T &value() & noexcept { + return *m_ptr; } - template - constexpr const U *get() const noexcept { - return m_ptr; + constexpr const T &value() const & noexcept { + return *m_ptr; + } + + constexpr T &&value() && noexcept { + return *m_ptr; + } + + constexpr const T &&value() const && noexcept { + return *m_ptr; } constexpr T &operator*() & noexcept { @@ -117,6 +123,7 @@ class Optional { template constexpr T &emplace(Args &&...args) { + reset(); if (std::is_constant_evaluated()) { m_ptr = new T(ox::forward(args)...); } else { @@ -128,6 +135,7 @@ class Optional { template constexpr T &emplace_subclass(Args &&...args) { static_assert(sizeof(U) <= buffSize, "Subclass is too large for this Optional"); + reset(); if (std::is_constant_evaluated()) { m_ptr = new U(ox::forward(args)...); } else { @@ -148,8 +156,8 @@ class Optional { constexpr void reset() noexcept { if (std::is_constant_evaluated()) { ox::safeDelete(m_ptr); - } else { - get()->~T(); + } else if (has_value()) { + value().~T(); } m_ptr = nullptr; }