0026549: Provide move constructors and operators for basic classes
authorabv <abv@opencascade.com>
Tue, 11 Aug 2015 20:01:05 +0000 (23:01 +0300)
committerabv <abv@opencascade.com>
Sat, 20 Feb 2016 07:10:13 +0000 (10:10 +0300)
Move constructor and operator added for opencascade::handle<>

src/Standard/Standard_Handle.hxx

index 23b075b..257b9a8 100644 (file)
@@ -69,6 +69,12 @@ namespace opencascade {
       BeginScope();
     }
 
+    //! Move constructor
+    handle (handle&& theHandle) : entity(theHandle.entity)
+    {
+      theHandle.entity = 0;
+    }
+
     //! Destructor
     ~handle ()
     {
@@ -104,6 +110,13 @@ namespace opencascade {
       return *this;
     }
 
+    //! Move operator
+    handle& operator= (handle&& theHandle)
+    {
+      std::swap (this->entity, theHandle.entity);
+      return *this;
+    }
+
     //! STL-like cast to pointer to referred object
     const T* get () const { return static_cast<const T*>(this->entity); }
 
@@ -220,6 +233,14 @@ namespace opencascade {
       BeginScope();
     }
 
+    //! Generalized move constructor
+    template <class T2, typename = typename std::enable_if <is_base_but_not_same <T, T2>::value>::type>
+    handle (handle<T2>&& theHandle)
+      : entity(theHandle.entity)
+    {
+      theHandle.entity = 0;
+    }
+
     //! Generalized assignment operator
     template <class T2, typename = typename std::enable_if <is_base_but_not_same <T, T2>::value>::type>
     handle operator = (const handle<T2>& theHandle)
@@ -228,6 +249,14 @@ namespace opencascade {
       return *this;
     }
 
+    //! Generalized move operator
+    template <class T2, typename = typename std::enable_if <is_base_but_not_same <T, T2>::value>::type>
+    handle& operator= (handle<T2>&& theHandle)
+    {
+      std::swap (this->entity, theHandle.entity);
+      return *this;
+    }
+
 #else
 
     //! Upcast to const reference to base type.
@@ -260,6 +289,14 @@ namespace opencascade {
       BeginScope();
     }
 
+    //! Generalized move constructor
+    template <class T2>
+    handle (handle<T2>&& theHandle, typename std::enable_if <is_base_but_not_same <T, T2>::value>::type* = nullptr)
+      : entity(theHandle.entity)
+    {
+      theHandle.entity = 0;
+    }
+
     //! Generalized assignment operator.
     template <class T2>
     handle operator = (const handle<T2>& theHandle)
@@ -270,6 +307,16 @@ namespace opencascade {
       return *this;
     }
 
+    //! Generalized move operator
+    template <class T2>
+    handle& operator= (handle<T2>&& theHandle)
+    {
+      std::enable_if <is_base_but_not_same <T, T2>::value, void*>::type aTypeCheckHelperVar;
+      (void)aTypeCheckHelperVar;
+      std::swap (this->entity, theHandle.entity);
+      return *this;
+    }
+
 #else
 
     //! Upcast to const reference to base type.