diff --git a/src/Chromosome.cpp b/src/Chromosome.cpp index 4d6648a..51038af 100644 --- a/src/Chromosome.cpp +++ b/src/Chromosome.cpp @@ -47,8 +47,6 @@ Chromosome::Chromosome(const Chromosome& father, const Chromosome& mother) Chromosome::Chromosome(const Chromosome& other) { - // reserve to other's size/capacity? - this->genes.reserve(other.genes.size()); for (auto& ptr : other.genes) { @@ -59,8 +57,6 @@ Chromosome::Chromosome(const Chromosome& other) Chromosome& Chromosome::operator=(const Chromosome& other) { - // reserve to other's size/capacity? - this->genes.clear(); this->genes.reserve(other.genes.size()); @@ -74,6 +70,22 @@ Chromosome& Chromosome::operator=(const Chromosome& other) } +Chromosome::Chromosome(Chromosome&& other) +{ + std::swap(this->genes, other.genes); +} + + +Chromosome& Chromosome::operator=(Chromosome&& other) +{ + this->genes.clear(); + + std::swap(this->genes, other.genes); + + return *this; +} + + void Chromosome::draw(sf::RenderTarget& target, sf::RenderStates states) const { for (auto& geneptr : this->genes) { diff --git a/src/Chromosome.hpp b/src/Chromosome.hpp index c1e69e2..3988424 100644 --- a/src/Chromosome.hpp +++ b/src/Chromosome.hpp @@ -20,9 +20,10 @@ public: Chromosome(); // create empty chromosome Chromosome(const Chromosome& father, const Chromosome& mother); // crossover - Chromosome(const Chromosome& father); // copy constructor -// Chromosome& operator=(const Chromosome& chr) = delete; // copy assignment operator - Chromosome& operator=(const Chromosome& chr); // copy assignment operator + Chromosome(const Chromosome& other); // copy constructor + Chromosome& operator=(const Chromosome& other); // copy assignment operator + Chromosome(Chromosome&& other); // copy constructor + Chromosome& operator=(Chromosome&& other); // copy assignment operator virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;