When should we use unique pointers?
Show answer and explanation
Use std::unique_ptr when one object exclusively owns a dynamically allocated resource and ownership may be transferred. Prefer direct objects when allocation or nullable ownership is unnecessary, and pass observers as references or raw pointers.
Use std::unique_ptr when one object exclusively owns a dynamically allocated resource and ownership may be transferred. Prefer direct objects when allocation or nullable ownership is unnecessary, and pass observers as references or raw pointers.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.