aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-10-05 21:06:44 +0200
committerStefan Boberg <[email protected]>2021-10-05 21:06:44 +0200
commitf98e80b6e39882e46caa850ea10a4869418d30ae (patch)
tree2d0faa40370fb6864b6563c231603a6492392a68
parentMerge branch 'main' of https://github.com/EpicGames/zen into main (diff)
downloadzen-f98e80b6e39882e46caa850ea10a4869418d30ae.tar.xz
zen-f98e80b6e39882e46caa850ea10a4869418d30ae.zip
Added Ref<> constructor which allows casting from derived types to parent types
-rw-r--r--zencore/include/zencore/refcount.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/zencore/include/zencore/refcount.h b/zencore/include/zencore/refcount.h
index 320718f5b..7167ab3b5 100644
--- a/zencore/include/zencore/refcount.h
+++ b/zencore/include/zencore/refcount.h
@@ -4,6 +4,8 @@
#include "atomic.h"
#include "zencore.h"
+#include <concepts>
+
namespace zen {
/**
@@ -114,6 +116,10 @@ public:
inline Ref(T* Ptr) : m_Ref(Ptr) { m_Ref && m_Ref->AddRef(); }
inline ~Ref() { m_Ref && m_Ref->Release(); }
+ template<typename DerivedType>
+ requires std::derived_from<DerivedType, T>
+ inline Ref(const Ref<DerivedType>& Rhs) : Ref(Rhs.m_Ref) {}
+
[[nodiscard]] inline bool IsNull() const { return m_Ref == nullptr; }
inline explicit operator bool() const { return m_Ref != nullptr; }
inline T* operator->() const { return m_Ref; }
@@ -152,6 +158,9 @@ public:
private:
T* m_Ref = nullptr;
+
+ template<class T>
+ friend class Ref;
};
void refcount_forcelink();