October 2004
Intermediate to advanced
240 pages
6h 22m
English
swap (and provide it correctly)swap is both a lightweight and a workhorse: Consider providing a swap function to efficiently and infallibly swap the internals of this object with another’s. Such a function can be handy for implementing a number of idioms, from smoothly moving objects around to implementing assignment easily to providing a guaranteed commit function that enables strongly error-safe calling code. (See also Item 51.)
A swap function typically looks like this, where U is some user-defined type:

For primitive types and for standard containers, std::swap will do. ...