diff options
| author | Stefan Boberg <[email protected]> | 2021-10-05 21:06:44 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-10-05 21:06:44 +0200 |
| commit | f98e80b6e39882e46caa850ea10a4869418d30ae (patch) | |
| tree | 2d0faa40370fb6864b6563c231603a6492392a68 | |
| parent | Merge branch 'main' of https://github.com/EpicGames/zen into main (diff) | |
| download | zen-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.h | 9 |
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(); |