From f11d44246cb3a46317d29258a0169dfacdf15eec Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 30 Jun 2012 00:33:36 +0200 Subject: [PATCH] add safe_ptr::operator=(safe_ptr&&) and safe_ptr::reset(T*) --- src/utils.hh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/utils.hh b/src/utils.hh index ec2ac364..6555e320 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -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; }