Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 910582b5 authored by BRAMAS Berenger's avatar BRAMAS Berenger
Browse files

Add copy constructor and operator from rvalue objects for the list and vectro

parent 548c9b34
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment