A StackOverflow user explains the copy and swap idiom: Link