From fabbb9f53188c93939b29f62c59ff9b7bb6990b0 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 10 Jul 2023 09:41:39 +0300 Subject: [PATCH] BAN: RefPtr can be constructed from other types --- BAN/include/BAN/RefPtr.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/BAN/include/BAN/RefPtr.h b/BAN/include/BAN/RefPtr.h index e717485d..9d9364a9 100644 --- a/BAN/include/BAN/RefPtr.h +++ b/BAN/include/BAN/RefPtr.h @@ -53,7 +53,6 @@ namespace BAN if (m_pointer) m_pointer->ref(); } - ~RefPtr() { clear(); } template @@ -75,6 +74,10 @@ namespace BAN RefPtr(const RefPtr& other) { *this = other; } RefPtr(RefPtr&& other) { *this = move(other); } + template + RefPtr(const RefPtr& other) { *this = other; } + template + RefPtr(RefPtr&& other) { *this = move(other); } RefPtr& operator=(const RefPtr& other) { @@ -93,6 +96,25 @@ namespace BAN return *this; } + template + RefPtr& operator=(const RefPtr& other) + { + clear(); + m_pointer = other.m_pointer; + if (m_pointer) + m_pointer->ref(); + return *this; + } + + template + RefPtr& operator=(RefPtr&& other) + { + clear(); + m_pointer = other.m_pointer; + other.m_pointer = nullptr; + return *this; + } + T* ptr() { ASSERT(!empty()); return m_pointer; } const T* ptr() const { ASSERT(!empty()); return m_pointer; } @@ -114,6 +136,9 @@ namespace BAN private: T* m_pointer = nullptr; + + template + friend class RefPtr; }; }