Final interview at an HFT shop: a CTO who hasn't slept, an HR person who thinks C++ is 'like Python but older', and you. The CTO yawns: 'std::unique_ptr. Write your own. No std::.' HR nods knowingly. You have 30 minutes and a marker that's almost dry.
Implement a minimal UniquePtr<T> — a move-only owning smart pointer. This is one of the most common C++ interview questions: it tests your understanding of ownership, move semantics, and the rule of five.
release() gives up ownership without deletingreset() deletes the current object and takes a new oneoperator bool reports whether a pointer is heldunique_ptr forbid copying?unique_ptr?release() and reset()?= delete the copy constructor and copy assignment to make it move-only.
Move operations steal the pointer and null the source; the destructor just deletes it.
Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.