summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-05-06 21:36:31 +0100
committerVaxry <vaxry@vaxry.net>2024-05-06 21:36:31 +0100
commit0c446ec5f4c39599ea97cb703dd3ac7718fb9169 (patch)
treed774e32c24d7ed4ea28c7bebf30feaba7f37ec62 /src
parentfa69de8ab6cc17bb763a1586c55847c5d5a82a83 (diff)
memory: fix SP/WP hierarchy templates
Diffstat (limited to 'src')
-rw-r--r--src/helpers/memory/SharedPtr.hpp16
-rw-r--r--src/helpers/memory/WeakPtr.hpp18
2 files changed, 19 insertions, 15 deletions
diff --git a/src/helpers/memory/SharedPtr.hpp b/src/helpers/memory/SharedPtr.hpp
index ff9b4a45..77f5164a 100644
--- a/src/helpers/memory/SharedPtr.hpp
+++ b/src/helpers/memory/SharedPtr.hpp
@@ -122,7 +122,9 @@ template <typename T>
class CSharedPointer {
public:
template <typename X>
- using validHierarchy = typename std::enable_if<std::is_assignable<T*, X*>::value>;
+ using validHierarchy = typename std::enable_if<std::is_assignable<CSharedPointer<T>&, X>::value, CSharedPointer&>::type;
+ template <typename X>
+ using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type;
/* creates a new shared pointer managing a resource
avoid calling. Could duplicate ownership. Prefer makeShared */
@@ -132,7 +134,7 @@ class CSharedPointer {
}
/* creates a shared pointer from a reference */
- template <typename U, typename = validHierarchy<U>>
+ template <typename U, typename = isConstructible<U>>
CSharedPointer(const CSharedPointer<U>& ref) noexcept {
impl_ = ref.impl_;
increment();
@@ -143,7 +145,7 @@ class CSharedPointer {
increment();
}
- template <typename U, typename = validHierarchy<U>>
+ template <typename U, typename = isConstructible<U>>
CSharedPointer(CSharedPointer<U>&& ref) noexcept {
std::swap(impl_, ref.impl_);
}
@@ -178,8 +180,8 @@ class CSharedPointer {
decrement();
}
- template <typename U, typename = validHierarchy<U>>
- CSharedPointer<T>& operator=(const CSharedPointer<U>& rhs) {
+ template <typename U>
+ validHierarchy<const CSharedPointer<U>&> operator=(const CSharedPointer<U>& rhs) {
if (impl_ == rhs.impl_)
return *this;
@@ -199,8 +201,8 @@ class CSharedPointer {
return *this;
}
- template <typename U, typename = validHierarchy<U>>
- CSharedPointer<T>& operator=(CSharedPointer<U>&& rhs) {
+ template <typename U>
+ validHierarchy<const CSharedPointer<U>&> operator=(CSharedPointer<U>&& rhs) {
std::swap(impl_, rhs.impl_);
return *this;
}
diff --git a/src/helpers/memory/WeakPtr.hpp b/src/helpers/memory/WeakPtr.hpp
index 677fddf4..f0e72146 100644
--- a/src/helpers/memory/WeakPtr.hpp
+++ b/src/helpers/memory/WeakPtr.hpp
@@ -14,10 +14,12 @@ template <typename T>
class CWeakPointer {
public:
template <typename X>
- using validHierarchy = typename std::enable_if<std::is_assignable<T*, X*>::value>;
+ using validHierarchy = typename std::enable_if<std::is_assignable<CWeakPointer<T>&, X>::value, CWeakPointer&>::type;
+ template <typename X>
+ using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type;
/* create a weak ptr from a reference */
- template <typename U, typename = validHierarchy<U>>
+ template <typename U, typename = isConstructible<U>>
CWeakPointer(const CSharedPointer<U>& ref) noexcept {
if (!ref.impl_)
return;
@@ -27,7 +29,7 @@ class CWeakPointer {
}
/* create a weak ptr from another weak ptr */
- template <typename U, typename = validHierarchy<U>>
+ template <typename U, typename = isConstructible<U>>
CWeakPointer(const CWeakPointer<U>& ref) noexcept {
if (!ref.impl_)
return;
@@ -44,7 +46,7 @@ class CWeakPointer {
incrementWeak();
}
- template <typename U, typename = validHierarchy<U>>
+ template <typename U, typename = isConstructible<U>>
CWeakPointer(CWeakPointer<U>&& ref) noexcept {
std::swap(impl_, ref.impl_);
}
@@ -54,8 +56,8 @@ class CWeakPointer {
}
/* create a weak ptr from another weak ptr with assignment */
- template <typename U, typename = validHierarchy<U>>
- CWeakPointer<T>& operator=(const CWeakPointer<U>& rhs) {
+ template <typename U>
+ validHierarchy<const CWeakPointer<U>&> operator=(const CWeakPointer<U>& rhs) {
if (impl_ == rhs.impl_)
return *this;
@@ -76,8 +78,8 @@ class CWeakPointer {
}
/* create a weak ptr from a shared ptr with assignment */
- template <typename U, typename = validHierarchy<U>>
- CWeakPointer<T>& operator=(const CSharedPointer<U>& rhs) {
+ template <typename U>
+ validHierarchy<const CWeakPointer<U>&> operator=(const CSharedPointer<U>& rhs) {
if ((uintptr_t)impl_ == (uintptr_t)rhs.impl_)
return *this;