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_ptrwas developed in C++11 as a replacement forstd::auto_ptr- That a
std::unique_ptrhas 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_ptris the go to structure
What I would like to know:
- Is using a
std::unique_ptrever 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_ptrless favorable
overall? - If a
std::shared_ptrwould suffice for dynamic memory management in nearly every
situation, why does having at my disposal astd::unique_ptrmatter (again, other
than uniqueness)?
No comments:
Post a Comment