SharedPtr: Add operator=
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
bd4b05e534
commit
4fa33a9689
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
#include <luna/Alloc.h>
|
||||
#include <luna/Atomic.h>
|
||||
#include <luna/DebugLog.h>
|
||||
#include <luna/Result.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
|
||||
{
|
||||
return m_ptr;
|
||||
|
Loading…
Reference in New Issue
Block a user