[ox/std] Fix UniquePtr comparison operators to take const references to avoid copying

This commit is contained in:
Gary Talent 2021-04-25 02:33:39 -05:00
parent 5e78289cbc
commit 356d6a5036

View File

@ -44,15 +44,17 @@ class UniquePtr {
return m_t; return m_t;
} }
constexpr void reset(UniquePtr &&other = UniquePtr()) { template<typename U>
constexpr void reset(UniquePtr<U> &&other = UniquePtr()) {
auto t = m_t; auto t = m_t;
m_t = other.m_t; m_t = other.m_t;
other.m_t = nullptr; other.m_t = nullptr;
delete t; delete t;
} }
constexpr UniquePtr &operator=(UniquePtr &&other) { template<typename U>
reset(ox::move(other)); constexpr UniquePtr &operator=(UniquePtr<U> &&other) {
reset(move(other));
return *this; return *this;
} }
@ -71,33 +73,33 @@ class UniquePtr {
}; };
template<typename T> template<typename T>
constexpr bool operator==(const UniquePtr<T> p1, const UniquePtr<T> p2) noexcept { constexpr bool operator==(const UniquePtr<T> &p1, const UniquePtr<T> &p2) noexcept {
return p1.get() == p2.get(); return p1.get() == p2.get();
} }
template<typename T> template<typename T>
constexpr bool operator==(const UniquePtr<T> p1, std::nullptr_t) noexcept { constexpr bool operator==(const UniquePtr<T> &p1, std::nullptr_t) noexcept {
return p1.get(); return p1.get();
} }
template<typename T> template<typename T>
constexpr bool operator==(std::nullptr_t, const UniquePtr<T> p2) noexcept { constexpr bool operator==(std::nullptr_t, const UniquePtr<T> &p2) noexcept {
return p2.get(); return p2.get();
} }
template<typename T> template<typename T>
constexpr bool operator!=(const UniquePtr<T> p1, const UniquePtr<T> p2) noexcept { constexpr bool operator!=(const UniquePtr<T> &p1, const UniquePtr<T> &p2) noexcept {
return p1.get() != p2.get(); return p1.get() != p2.get();
} }
template<typename T> template<typename T>
constexpr bool operator!=(const UniquePtr<T> p1, std::nullptr_t) noexcept { constexpr bool operator!=(const UniquePtr<T> &p1, std::nullptr_t) noexcept {
return !p1.get(); return !p1.get();
} }
template<typename T> template<typename T>
constexpr bool operator!=(std::nullptr_t, const UniquePtr<T> p2) noexcept { constexpr bool operator!=(std::nullptr_t, const UniquePtr<T> &p2) noexcept {
return !p2.get(); return !p2.get();
} }