What are recommended uses of a std::unique_ptr
as to specifically where, when, and how is it is best used?
I discovered:
I already know:
std::unique_ptr
was developed in C++11 as a replacement forstd::auto_ptr
- That a
std::unique_ptr
has no reference counting and "owns" object it points to - There is no copy/assign with a
std::unique_ptr
- When I need a unique pointer,
std::unique_ptr
is the go to structure
What I would like to know:
- Is using a
std::unique_ptr
ever preferable (other than uniqueness) to something
else? What do I gain in this situation? - If so, under what circumstances and when?
- Given the need for move semantics, would this make a
std::unique_ptr
less favorable
overall? - If a
std::shared_ptr
would suffice for dynamic memory management in nearly every
situation, why does having at my disposal astd::unique_ptr
matter (again, other
than uniqueness)?
No comments:
Post a Comment