Copy-and-Swap Idiom
Learned in CS247.
We use the Copy-and-Swap Idiom to address potential code duplication between copy constructor and copy assignment operator.
Used in the Copy Assignment Operator (after copy constructor is implemented)
Node& Node::operator=(const Node& other) {
Node tmp{other};
std::swap(data, tmp.data);
std::swap(next, tmp.next);
return *this;
}
https://stackoverflow.com/questions/3279543/what-is-the-copy-and-swap-idiom