Skip to main content

Practice · 1 of 2

Swap ownership between two unique_ptrs

CHALLENGE
Difficulty: intermediate+25 XP

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.

Back to lesson: Practice: shared/weak practice