diff --git a/BAN/include/BAN/RefPtr.h b/BAN/include/BAN/RefPtr.h index 9f83ceb5..773d0dd1 100644 --- a/BAN/include/BAN/RefPtr.h +++ b/BAN/include/BAN/RefPtr.h @@ -2,9 +2,9 @@ #include #include +#include #include #include -#include namespace BAN { @@ -129,14 +129,9 @@ namespace BAN return *this; } - T* ptr() { ASSERT(!empty()); return m_pointer; } - const T* ptr() const { ASSERT(!empty()); return m_pointer; } - - T& operator*() { return *ptr(); } - const T& operator*() const { return *ptr(); } - - T* operator->() { return ptr(); } - const T* operator->() const { return ptr(); } + T* ptr() const { return m_pointer; } + T& operator*() const { ASSERT(!empty()); return *ptr(); } + T* operator->() const { ASSERT(!empty()); return ptr(); } bool operator==(RefPtr other) const { return m_pointer == other.m_pointer; } bool operator!=(RefPtr other) const { return m_pointer != other.m_pointer; } @@ -158,4 +153,13 @@ namespace BAN friend class RefPtr; }; + template + struct hash> + { + constexpr hash_t operator()(const RefPtr& ptr) const + { + return hash()(ptr.ptr()); + } + }; + } diff --git a/BAN/include/BAN/UniqPtr.h b/BAN/include/BAN/UniqPtr.h index 7d21467b..cc353f62 100644 --- a/BAN/include/BAN/UniqPtr.h +++ b/BAN/include/BAN/UniqPtr.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include namespace BAN @@ -53,32 +54,12 @@ namespace BAN return *this; } - T& operator*() - { - ASSERT(m_pointer); - return *m_pointer; - } + T* ptr() const { return m_pointer; } + T& operator*() const { ASSERT(!empty()); return *ptr(); } + T* operator->() const { ASSERT(!empty()); return ptr(); } - const T& operator*() const - { - ASSERT(m_pointer); - return *m_pointer; - } - - T* operator->() - { - ASSERT(m_pointer); - return m_pointer; - } - - const T* operator->() const - { - ASSERT(m_pointer); - return m_pointer; - } - - T* ptr() { return m_pointer; } - const T* ptr() const { return m_pointer; } + bool empty() const { return m_pointer == nullptr; } + explicit operator bool() const { return m_pointer; } void clear() { @@ -87,8 +68,6 @@ namespace BAN m_pointer = nullptr; } - operator bool() const { return m_pointer != nullptr; } - private: T* m_pointer = nullptr; @@ -96,4 +75,13 @@ namespace BAN friend class UniqPtr; }; + template + struct hash> + { + constexpr hash_t operator()(const UniqPtr& ptr) const + { + return hash()(ptr.ptr()); + } + }; + }