diff --git a/src/Standard/Standard_Handle.hxx b/src/Standard/Standard_Handle.hxx index 23b075bc14..257b9a8284 100644 --- a/src/Standard/Standard_Handle.hxx +++ b/src/Standard/Standard_Handle.hxx @@ -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(this->entity); } @@ -220,6 +233,14 @@ namespace opencascade { BeginScope(); } + //! Generalized move constructor + template ::value>::type> + handle (handle&& theHandle) + : entity(theHandle.entity) + { + theHandle.entity = 0; + } + //! Generalized assignment operator template ::value>::type> handle operator = (const handle& theHandle) @@ -228,6 +249,14 @@ namespace opencascade { return *this; } + //! Generalized move operator + template ::value>::type> + handle& operator= (handle&& 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 + handle (handle&& theHandle, typename std::enable_if ::value>::type* = nullptr) + : entity(theHandle.entity) + { + theHandle.entity = 0; + } + //! Generalized assignment operator. template handle operator = (const handle& theHandle) @@ -270,6 +307,16 @@ namespace opencascade { return *this; } + //! Generalized move operator + template + handle& operator= (handle&& theHandle) + { + std::enable_if ::value, void*>::type aTypeCheckHelperVar; + (void)aTypeCheckHelperVar; + std::swap (this->entity, theHandle.entity); + return *this; + } + #else //! Upcast to const reference to base type.