From 910582b516dcad4a601083e9dfbe9a6e49e986ec Mon Sep 17 00:00:00 2001 From: Berenger Bramas <Berenger.Bramas@inria.fr> Date: Tue, 24 Mar 2015 08:32:58 +0100 Subject: [PATCH] Add copy constructor and operator from rvalue objects for the list and vectro --- Src/Containers/FList.hpp | 28 ++++++++++++++++++++++++++++ Src/Containers/FVector.hpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/Src/Containers/FList.hpp b/Src/Containers/FList.hpp index 8937ecbf7..1a896710f 100755 --- a/Src/Containers/FList.hpp +++ b/Src/Containers/FList.hpp @@ -96,6 +96,34 @@ public: copy(other); } + /** + * Copy operator + * This will clear the current list before copying + * @param other the source list + * @return the current list as a reference + */ + FList& operator=(FList&& other){ + if(&other != this){ + clear(); + root = other.root; + size = other.size; + other.root = nullptr; + other.size = 0; + } + return *this; + } + + /** + * Copy constructor + * @param other the source/original list + */ + FList(FList&& other): root(nullptr) , size(0) { + root = other.root; + size = other.size; + other.root = nullptr; + other.size = 0; + } + /** * To clear the list * Size is 0 after calling this function diff --git a/Src/Containers/FVector.hpp b/Src/Containers/FVector.hpp index 7c228dfb5..a4982cbb2 100755 --- a/Src/Containers/FVector.hpp +++ b/Src/Containers/FVector.hpp @@ -77,6 +77,20 @@ public: } } + /** + * Copy constructor + * @param other original vector + * object must have an copy constructor + */ + FVector(FVector&& other): array(nullptr), capacity(0), index(0) { + array = other.array; + capacity = other.capacity; + index = other.index; + other.array = nullptr; + other.capacity = 0; + other.index = 0; + } + /** Copy operator * @param other the original vector * @return this after copying data @@ -103,6 +117,23 @@ public: return *this; } + /** + *@brief Copy operator + */ + FVector& operator=(FVector&& other){ + if(&other != this){ + clear(); + delete [] reinterpret_cast< char* >(array); + array = other.array; + capacity = other.capacity; + index = other.index; + other.array = nullptr; + other.capacity = 0; + other.index = 0; + } + return (*this); + } + /** *@brief destructor */ -- GitLab