add safe_ptr::operator=(safe_ptr&&) and safe_ptr::reset(T*)
This commit is contained in:
parent
dfbda951d3
commit
f11d44246c
18
src/utils.hh
18
src/utils.hh
|
@ -76,10 +76,26 @@ public:
|
||||||
if (m_ptr)
|
if (m_ptr)
|
||||||
m_ptr->inc_safe_count();
|
m_ptr->inc_safe_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
safe_ptr& operator=(safe_ptr&& other)
|
||||||
|
{
|
||||||
|
if (m_ptr != other.m_ptr)
|
||||||
|
{
|
||||||
|
if (m_ptr)
|
||||||
|
m_ptr->dec_safe_count();
|
||||||
|
m_ptr = other.m_ptr;
|
||||||
|
other.m_ptr = nullptr;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset(T* ptr)
|
||||||
|
{
|
||||||
|
*this = safe_ptr(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
bool operator== (const safe_ptr& other) const { return m_ptr == other.m_ptr; }
|
bool operator== (const safe_ptr& other) const { return m_ptr == other.m_ptr; }
|
||||||
bool operator!= (const safe_ptr& other) const { return m_ptr != other.m_ptr; }
|
bool operator!= (const safe_ptr& other) const { return m_ptr != other.m_ptr; }
|
||||||
bool operator== (T* ptr) const { return m_ptr == ptr; }
|
bool operator== (T* ptr) const { return m_ptr == ptr; }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user