๐ WAYPOINT LESSON
Checkpoint: Ownership Transfer
โญโญ intermediateโณ 35 min read๐ Lesson 111 of 204
An Inventory whose take() moves a unique_ptr out of a vector โ the exact mechanics of ownership leaving a container.
take() is the exam because it is the precise dance ownership teaches:
- find the slot by name
auto out = std::move(*it);โ ownership leaves the vector; the slot now holds an emptyunique_ptritems_.erase(it);โ remove the empty husk- return
out
Skipping step 2 destroys the item; skipping step 3 leaves a nullptr hole in the container. Both mistakes are silent at compile time โ which is why the tests check size, identity, and containment after the call.
This is the same dance std::vector::erase-with-move, node removal in
linked structures, and job queues all perform. Learn it once here and you
will recognize it everywhere.