The implementations of the copy operator and copy constructor (not moving) are used with the swap() method function closed in operator=() , respectively, the copy constructor is also called in the operator to create a temporary object.
Now I add to the class a moving assignment operator and constructor. For example:
MyClass::MyClass(MyClass&& other) { *this = std::move(other); // через оператор? } MyClass& MyClass::operator=(MyClass&& rhs) { rhs.swap(*this); // или this->swap(rhs); Solution().swap(rhs); // это ок return *this; } So I wonder if this implementation is optimal, in particular, here the operator is already using k, is that not bad? It is possible to make initialization lists in, for example:
MyClass::MyClass(MyClass&& other) : value_1(std::move(other.value_1)), value_2(std::move(other.value_2)) {} Will it give any advantage? Please write what is the best option, in your opinion, the implementation of these two specials. functions.