From 356d6a5036ca007a726571d961344cfbff233a8a Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 25 Apr 2021 02:33:39 -0500 Subject: [PATCH] [ox/std] Fix UniquePtr comparison operators to take const references to avoid copying --- deps/ox/src/ox/std/memory.hpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/deps/ox/src/ox/std/memory.hpp b/deps/ox/src/ox/std/memory.hpp index 543a711f..0337ba56 100644 --- a/deps/ox/src/ox/std/memory.hpp +++ b/deps/ox/src/ox/std/memory.hpp @@ -44,15 +44,17 @@ class UniquePtr { return m_t; } - constexpr void reset(UniquePtr &&other = UniquePtr()) { + template + constexpr void reset(UniquePtr &&other = UniquePtr()) { auto t = m_t; m_t = other.m_t; other.m_t = nullptr; delete t; } - constexpr UniquePtr &operator=(UniquePtr &&other) { - reset(ox::move(other)); + template + constexpr UniquePtr &operator=(UniquePtr &&other) { + reset(move(other)); return *this; } @@ -71,33 +73,33 @@ class UniquePtr { }; template -constexpr bool operator==(const UniquePtr p1, const UniquePtr p2) noexcept { +constexpr bool operator==(const UniquePtr &p1, const UniquePtr &p2) noexcept { return p1.get() == p2.get(); } template -constexpr bool operator==(const UniquePtr p1, std::nullptr_t) noexcept { +constexpr bool operator==(const UniquePtr &p1, std::nullptr_t) noexcept { return p1.get(); } template -constexpr bool operator==(std::nullptr_t, const UniquePtr p2) noexcept { +constexpr bool operator==(std::nullptr_t, const UniquePtr &p2) noexcept { return p2.get(); } template -constexpr bool operator!=(const UniquePtr p1, const UniquePtr p2) noexcept { +constexpr bool operator!=(const UniquePtr &p1, const UniquePtr &p2) noexcept { return p1.get() != p2.get(); } template -constexpr bool operator!=(const UniquePtr p1, std::nullptr_t) noexcept { +constexpr bool operator!=(const UniquePtr &p1, std::nullptr_t) noexcept { return !p1.get(); } template -constexpr bool operator!=(std::nullptr_t, const UniquePtr p2) noexcept { +constexpr bool operator!=(std::nullptr_t, const UniquePtr &p2) noexcept { return !p2.get(); }