Question about linked-list copy ctor
What is the typical way of handling list copying?
Do you normally clear() and then swap(const List& rhs)?
What I don't understand about that is clear() should effectively delete all the nodes in the list, but what happens with swap() after clear()? Does the rhs list receive a list that doesn't exist?
My first thought then is to handle it in this manner:
Code:
template <typename T>
List<T>::List(const List& rhs_l) : head(0), tail(0), sizeOfList(0){
clear();
for(Iter i(rhs_l.head); i != end(); i++){
push_back(*i);
}
}