- What does swap do?
The swap function exchanges the state of the two objects. After the swap call, the objects should remain unchanged, except for the names they are accessed by.
- How is swap used in exception-safe programs?
Swap is usually employed in programs that provide commit-or-rollback semantics; a temporary copy of the result is created first, then swapped into its final destination only if no errors were detected.
- Why should the swap function be non-throwing?
The use of swap to provide commit-or-rollback semantics assumes that the swap operation itself cannot throw an exception or otherwise fail and leave the swapped objects in an undefined state.
- Should a member or a non-member implementation of swap be preferred?
A non-member swap function should always be provided, to ensure that the calls to non-member swap are executed correctly. A member swap function...