diff --git a/alib2/src/regexp/Alternation.cpp b/alib2/src/regexp/Alternation.cpp index 8662f584038f55fd0946941b120b14504e20f138..9b3bd1e8214ff28a5b3c2e179f8a9ce975290d27 100644 --- a/alib2/src/regexp/Alternation.cpp +++ b/alib2/src/regexp/Alternation.cpp @@ -19,24 +19,27 @@ Alternation::Alternation(const Alternation& other) { } } +Alternation::Alternation(Alternation&& other) noexcept : elements(std::move(other.elements)) { + other.elements.clear(); +} + Alternation& Alternation::operator=(const Alternation& other) { if (this == &other) { return *this; } - for (auto element : elements) { - delete element; - } - elements.clear(); + *this = Alternation(other); - for (const auto& element : other.elements) { - elements.push_back(element->clone()); - } + return *this; +} +Alternation& Alternation::operator=(Alternation&& other) { + std::swap(this->elements, other.elements); + return *this; } -Alternation::~Alternation() { +Alternation::~Alternation() noexcept { for (auto element : elements) { delete element; } diff --git a/alib2/src/regexp/Alternation.h b/alib2/src/regexp/Alternation.h index 6b14f5bbd2006d871b266180ceb861816cd051bc..098e601f8461092a9dbd5967c1cc048db5507964 100644 --- a/alib2/src/regexp/Alternation.h +++ b/alib2/src/regexp/Alternation.h @@ -23,8 +23,10 @@ private: public: Alternation(); Alternation(const Alternation& other); + Alternation(Alternation&& other) noexcept; Alternation& operator =(const Alternation& other); - ~Alternation(); + Alternation& operator =(Alternation&& other); + ~Alternation() noexcept; /** * @return list of operands