From fedafb9352c2877c5983e90834ffba0fff80ff15 Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Thu, 9 Nov 2017 21:08:00 +0100 Subject: [PATCH] SGSharedPtr: add move constructor and move assignment operator --- simgear/structure/SGSharedPtr.hxx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/simgear/structure/SGSharedPtr.hxx b/simgear/structure/SGSharedPtr.hxx index 3afcfc91..181dcbb6 100644 --- a/simgear/structure/SGSharedPtr.hxx +++ b/simgear/structure/SGSharedPtr.hxx @@ -56,6 +56,8 @@ public: { get(_ptr); } SGSharedPtr(const SGSharedPtr& p) : _ptr(p.get()) { get(_ptr); } + SGSharedPtr(SGSharedPtr&& other) : SGSharedPtr() + { swap(other); } template SGSharedPtr(const SGSharedPtr& p) : _ptr(p.get()) { get(_ptr); } @@ -64,9 +66,11 @@ public: { reset(p.lock().get()); } ~SGSharedPtr(void) { reset(); } - - SGSharedPtr& operator=(const SGSharedPtr& p) - { reset(p.get()); return *this; } + + // This handles copy assignment using the copy-and-swap idiom, and also move + // assignment thanks to the move construtor. + SGSharedPtr& operator=(SGSharedPtr p) + { swap(p); return *this; } template SGSharedPtr& operator=(const SGSharedPtr& p) { reset(p.get()); return *this; }