liveBook · Manning

Std::unique_ptr

std::unique_ptr is a C++ standard-library smart pointer that provides exclusive ownership of a dynamically allocated object and manages its lifetime.

How 2 Manning books explain it

100 C++ Mistakes and How to Avoid Them

std::unique_ptr is a C++ standard-library smart pointer that provides exclusive ownership of a dynamically allocated object or array and automatically manages its lifetime.

How it is used
Uses exclusive ownership to replace raw-pointer resource management and simplify exception-safe lifetime handling.
How deep it goes
Explains object and array ownership, destructor removal, make_unique construction, and std::move transfer, but not custom deleters.
Examples
Demonstrates Buffer objects, dynamically allocated arrays, a raw-pointer double delete, and transfer between two unique_ptr instances.
What you can do after
Apply it via std::make_unique and std::move to construct, own, and transfer dynamically allocated objects or arrays.

Read how 100 C++ Mistakes and How to Avoid Them explains std::unique_ptr →

Learn C++ by Example

std::unique_ptr is a C++ standard library smart pointer that exclusively owns a dynamically allocated object and destroys it when ownership ends.

How it is used
Manages exclusive dynamic ownership in containers, polymorphic objects, and coroutine tasks.
How deep it goes
Explains RAII, deletion, copying, moving, member access, containers, and custom deleters, but not implementation internals.
Examples
Uses smart-pointer vectors, a polymorphic blob race, make_unique construction, and coroutine-handle cleanup.
What you can do after
Apply it via the C++ standard library to express exclusive ownership and automatic cleanup, including custom destruction.

Read how Learn C++ by Example explains std::unique_ptr →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.