diff --git a/deps/ox/src/ox/std/optional.hpp b/deps/ox/src/ox/std/optional.hpp index aa0f1f87..de302910 100644 --- a/deps/ox/src/ox/std/optional.hpp +++ b/deps/ox/src/ox/std/optional.hpp @@ -22,7 +22,7 @@ template class Optional { private: T *m_ptr = nullptr; - char m_data[buffSize] = {}; + AllocAlias m_data = {}; public: constexpr Optional() noexcept = default; @@ -32,7 +32,7 @@ class Optional { constexpr Optional(const Optional &other) { if (other.m_ptr) { - m_ptr = new(m_data) T(*other.m_ptr); + m_ptr = new(m_data.data()) T(*other.m_ptr); } } @@ -41,7 +41,7 @@ class Optional { m_ptr->~T(); } if (other.m_ptr) { - m_ptr = new(m_data) T(std::move(*other.m_ptr)); + m_ptr = new(m_data.data()) T(std::move(*other.m_ptr)); } } @@ -120,7 +120,7 @@ class Optional { if (std::is_constant_evaluated()) { m_ptr = new T(ox::forward(args)...); } else { - m_ptr = std::construct_at(reinterpret_cast(m_data), ox::forward(args)...); + m_ptr = std::construct_at(reinterpret_cast(m_data.data()), ox::forward(args)...); } return *m_ptr; } @@ -131,7 +131,7 @@ class Optional { if (std::is_constant_evaluated()) { m_ptr = new U(ox::forward(args)...); } else { - m_ptr = std::construct_at(reinterpret_cast(m_data), ox::forward(args)...); + m_ptr = std::construct_at(reinterpret_cast(m_data.data()), ox::forward(args)...); } return *m_ptr; } diff --git a/deps/ox/src/ox/std/types.hpp b/deps/ox/src/ox/std/types.hpp index 6f4dc8b5..7107530a 100644 --- a/deps/ox/src/ox/std/types.hpp +++ b/deps/ox/src/ox/std/types.hpp @@ -67,6 +67,14 @@ template struct alignas(alignof(T)) AllocAlias { char buff[sz]; constexpr AllocAlias() noexcept = default; + [[nodiscard]] + auto data() noexcept { + return reinterpret_cast(this); + } + [[nodiscard]] + auto data() const noexcept { + return reinterpret_cast(this); + } };