SGSharedPtr: add move constructor and move assignment operator

This commit is contained in:
Florent Rougon
2017-11-09 21:08:00 +01:00
parent 18f0484249
commit fedafb9352

View File

@@ -56,6 +56,8 @@ public:
{ get(_ptr); } { get(_ptr); }
SGSharedPtr(const SGSharedPtr& p) : _ptr(p.get()) SGSharedPtr(const SGSharedPtr& p) : _ptr(p.get())
{ get(_ptr); } { get(_ptr); }
SGSharedPtr(SGSharedPtr&& other) : SGSharedPtr()
{ swap(other); }
template<typename U> template<typename U>
SGSharedPtr(const SGSharedPtr<U>& p) : _ptr(p.get()) SGSharedPtr(const SGSharedPtr<U>& p) : _ptr(p.get())
{ get(_ptr); } { get(_ptr); }
@@ -65,8 +67,10 @@ public:
~SGSharedPtr(void) ~SGSharedPtr(void)
{ reset(); } { reset(); }
SGSharedPtr& operator=(const SGSharedPtr& p) // This handles copy assignment using the copy-and-swap idiom, and also move
{ reset(p.get()); return *this; } // assignment thanks to the move construtor.
SGSharedPtr& operator=(SGSharedPtr p)
{ swap(p); return *this; }
template<typename U> template<typename U>
SGSharedPtr& operator=(const SGSharedPtr<U>& p) SGSharedPtr& operator=(const SGSharedPtr<U>& p)
{ reset(p.get()); return *this; } { reset(p.get()); return *this; }