I read two articles on stackOverflow,one describing the copy and swap idiom and the other talking about move semantics,but I fail to see why we need to swap in the assignment operator when the move constructor or copy constructor has already done that for us
so from what I understand as explained if we use an lvalue the assignment operator will construct an object with the copy constructor if an rvalue it will construct an object with the move constructor,so lets say we choose the latter
lets say we have a function that swaps objects members and below is the assignment operator,so as I said lets say we have an rvalue first the operator= will construct an object with the move constructor so why so we need the swap function here??
we have already accomplished what we want we have made an object with the move constructor and "stolen or taken" the data we needed so whats the need for the extra swap?
aren't we just doing the same thing all over again just swapping?
here are the articles/threads
What is the copy-and-swap idiom?
dumb_array& operator=(dumb_array other) // (1)
{
swap(*this, other); // (2)
return *this;
}