[ox/std] Fix various issues with Optional copy and move constructors
This commit is contained in:
parent
edd21017d3
commit
1767821161
15
deps/ox/src/ox/std/optional.hpp
vendored
15
deps/ox/src/ox/std/optional.hpp
vendored
@ -32,16 +32,13 @@ class Optional {
|
||||
|
||||
constexpr Optional(const Optional &other) {
|
||||
if (other.m_ptr) {
|
||||
m_ptr = new(m_data.data()) T(*other.m_ptr);
|
||||
m_ptr = std::construct_at<T>(m_data.data(), *other.m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr Optional(const Optional &&other) noexcept {
|
||||
if (m_ptr) {
|
||||
m_ptr->~T();
|
||||
}
|
||||
constexpr Optional(Optional &&other) noexcept {
|
||||
if (other.m_ptr) {
|
||||
m_ptr = new(m_data.data()) T(std::move(*other.m_ptr));
|
||||
m_ptr = std::construct_at<T>(m_data.data(), std::move(*other.m_ptr));
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,7 +97,7 @@ class Optional {
|
||||
emplace();
|
||||
}
|
||||
*m_ptr = *other.m_ptr;
|
||||
} else if (m_ptr) {
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
return *this;
|
||||
@ -115,7 +112,7 @@ class Optional {
|
||||
emplace();
|
||||
}
|
||||
*m_ptr = std::move(*other.m_ptr);
|
||||
} else if (m_ptr) {
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
return *this;
|
||||
@ -153,7 +150,7 @@ class Optional {
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
constexpr void reset() noexcept {
|
||||
constexpr void reset() {
|
||||
if (std::is_constant_evaluated()) {
|
||||
ox::safeDelete(m_ptr);
|
||||
} else if (has_value()) {
|
||||
|
Loading…
Reference in New Issue
Block a user