Quote:Original post by ChaosEngine
...snip...
I'd disagree with that gotw article that copy construction should be implemented using an overloaded assignment op (or private copy function), as again, they are not the same thing. While it's initally fine if your class has POD's, if you add a UDT member that does something funny in it's copy/assignment you're in tonnes of trouble.
I'm having trouble understanding why that would get you into trouble. It would still use the UDT's assignment operator, so what's the problem?
On another note, if your class implements a faster swap, like std::vector, it would be nice if std::swap used it. Currently it's like so:
// This copies the vectors 3 times!
// vec1 into a temp vec (which requires an allocation)
// vec2 into vec1 (may require an allocation)
// temp into vec2 (may require an allocation)
std::swap(vec1, vec2);
// Swaps 2 pointers.
vec1.swap(vec2);