add safe_ptr::operator=(safe_ptr&&) and safe_ptr::reset(T*)

This commit is contained in:
Maxime Coste 2012-06-30 00:33:36 +02:00
parent dfbda951d3
commit f11d44246c

View File

@ -76,10 +76,26 @@ public:
if (m_ptr)
m_ptr->inc_safe_count();
}
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== (T* ptr) const { return m_ptr == ptr; }