liveBook · Manning

Std::unique_ptr

std::unique_ptr is a C++ standard-library class template that exclusively owns a dynamically allocated object or array 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 std::unique_ptr to replace manual management of exclusively owned dynamic resources.
How deep it goes
Works through object and array ownership, automatic cleanup, and ownership transfer with std::move.
Examples
Contrasts a double-deleted raw Buffer with a Buffer using unique pointers for itself and its array.
What you can do after
Apply std::unique_ptr and std::make_unique to manage an exclusive resource and transfer its ownership.

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 →

What to know first

Related concepts

Questions about std::unique_ptr

What is std::unique_ptr?

std::unique_ptr is a C++ standard-library class template that exclusively owns a dynamically allocated object or array and manages its lifetime.

Which Manning books explain std::unique_ptr?

100 C++ Mistakes and How to Avoid Them and Learn C++ by Example.

What should I know before learning std::unique_ptr?

Manning books that teach std::unique_ptr usually introduce destructor, move and reference first.

What is std::unique_ptr a kind of?

Std::unique_ptr is a kind of smart pointer. A smart pointer is a pointer-like object that manages or mediates access to a referenced resource, often providing ownership, lifetime, or safety behavior.

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.