What is this idiom and when should it be used? Which problems does it solve? Does the idiom change when C++11 is used?
Although it's been mentioned in many places, we didn't have any singular "what is it" question and answer, so here it is. Here is a partial list of places where it was previously mentioned:
- What are your favorite C++ Coding Style idioms: Copy-swap
- Copy constructor and = operator overload in C++: is a common function possible?
- What is copy elision and how it optimizes copy-and-swap idiom
- C++: dynamically allocating an array of objects?