Use the copy-and-swap idiom for ptr.