I c++ programming language 13.6.2 std::swap is used to implement move semantics the idea is below:
class greenCars{
public:
greenCars(){std::cout<<"DS\n";}
greenCars& operator=(const greenCars& other){
greenCars tmp;
swap(*this, tmp);
return *this;
}
greenCars(deutscheSchweine&& other){}
greenCars& operator=(greenCars&& other){
swap(*this, other);
return *this;
}
};
int main(){
greenCars ds;
greenCars ds2;
ds2 = ds;
I above example after calling assignment we can use move semantics to avid copying from temporary, but this example causes recursively calling move assignment. My question is can we use swap in move semantics but in some proper way?