SharedPtr: Add operator=
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2022-12-23 10:31:48 +01:00
parent bd4b05e534
commit 4fa33a9689
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <luna/Alloc.h> #include <luna/Alloc.h>
#include <luna/Atomic.h> #include <luna/Atomic.h>
#include <luna/DebugLog.h>
#include <luna/Result.h> #include <luna/Result.h>
#include <luna/ScopeGuard.h> #include <luna/ScopeGuard.h>
@ -54,6 +53,24 @@ template <typename T> class SharedPtr
} }
} }
SharedPtr<T>& operator=(const SharedPtr<T>& other)
{
if (&other == this) return *this;
if (m_ref_count && m_ref_count->unref())
{
delete m_ref_count;
delete m_ptr;
}
m_ptr = other.m_ptr;
m_ref_count = other.m_ref_count;
m_ref_count->ref();
return *this;
}
T* ptr() const T* ptr() const
{ {
return m_ptr; return m_ptr;