[glibmm] RefPtr: Add move constructor and move assignment operator.



commit 10898bc89ef57b2447b559af7e4e925739839f7d
Author: Murray Cumming <murrayc murrayc com>
Date:   Sat Jul 18 22:47:56 2015 +0200

    RefPtr: Add move constructor and move assignment operator.

 glib/glibmm/refptr.h |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/glib/glibmm/refptr.h b/glib/glibmm/refptr.h
index 79d05ce..fd57b36 100644
--- a/glib/glibmm/refptr.h
+++ b/glib/glibmm/refptr.h
@@ -68,6 +68,10 @@ public:
    */
   inline RefPtr(const RefPtr& src);
 
+  /** Move constructor
+   */
+  inline RefPtr(RefPtr&& src);
+
   /** Copy constructor (from different, but castable type).
    *
    * Increments the reference count.
@@ -85,6 +89,9 @@ public:
   /// Copy from another RefPtr:
   inline RefPtr& operator=(const RefPtr& src);
 
+  /// Move assignment operator:
+  inline RefPtr& operator=(RefPtr&& src);
+
   /** Copy from different, but castable type).
    *
    * Increments the reference count.
@@ -223,6 +230,14 @@ RefPtr<T_CppObject>::RefPtr(const RefPtr& src)
     pCppObject_->reference();
 }
 
+template <class T_CppObject> inline
+RefPtr<T_CppObject>::RefPtr(RefPtr&& src)
+:
+  pCppObject_ (src.pCppObject_)
+{
+  src.pCppObject_ = nullptr;
+}
+
 // The templated ctor allows copy construction from any object that's
 // castable.  Thus, it does downcasts:
 //   base_ref = derived_ref
@@ -280,6 +295,14 @@ RefPtr<T_CppObject>& RefPtr<T_CppObject>::operator=(const RefPtr& src)
   return *this;
 }
 
+template <class T_CppObject> inline
+RefPtr<T_CppObject>& RefPtr<T_CppObject>::operator=(RefPtr&& src)
+{
+  pCppObject_ = src.pCppObject_;
+  src.pCppObject_ = nullptr;
+  return *this;
+}
+
 template <class T_CppObject>
   template <class T_CastFrom>
 inline


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]