Skip to main content

Practice ยท 1 of 2

Swap ownership between two unique_ptrs

Implement template <typename T> void pointer_swap(std::unique_ptr<T>& a, std::unique_ptr<T>& b) exchanging the two owned objects. After the call, each unique_ptr owns what the other owned. Do not use std::swap โ€” implement the exchange with three std::moves.

Difficulty: intermediate

Back to lesson: Practice: shared/weak practice