Top "Unique-ptr" questions

std::unique_ptr is a smart pointer that retains sole ownership of an object through a pointer.

How to assign the address of an existing object to a smart pointer?

#include <memory> class bar{}; void foo(bar &object){ std::unique_ptr<bar> pointer = &object; } …

c++ smart-pointers c++14 unique-ptr
Can a unique_ptr take a nullptr value?

Is this code fragment valid? : unique_ptr<A> p(new A()); p = nullptr; That is, can I assign …

c++ c++11 pointers unique-ptr nullptr
Difference between boost::scoped_ptr<T> and std::unique_ptr<T>

Is the sole difference between boost::scoped_ptr<T> and std::unique_ptr<T> the fact …

c++ unique-ptr scoped-ptr
unique_ptr<T> lambda custom deleter for array specialization

I recently started porting lots of my existing C++ application code to over to C++11 and now that I am …

c++ lambda c++11 smart-pointers unique-ptr
Iterating through vector<unique_ptr<mytype>> using C++11 for() loops

I've got the following batch of code: std::vector<std::unique_ptr<AVLTree_GeeksforGeeks>> AVLArray(100000); /* Let's …

c++ c++11 vector unique-ptr
Alternatives of static_pointer_cast for unique_ptr

I understand that using static_pointer_cast with unique_ptr would lead to a shared ownership of the contained data. …

c++ c++11 casting shared-ptr unique-ptr
Iterating over a container of unique_ptr's

How does one access unique_ptr elements of a container (via an iterator) without taking ownership away from the container? …

c++ iterator containers unique-ptr
Recommended usage of std::unique_ptr

What are recommended uses of a std::unique_ptr as to specifically where, when, and how is it is best …

c++ c++11 smart-pointers unique-ptr
"Downcasting" unique_ptr<Base> to unique_ptr<Derived>

I have a series of factories that return unique_ptr<Base>. Under the hood, though, they are providing …

c++ c++11 smart-pointers factory-pattern unique-ptr
Why can't a weak_ptr be constructed from a unique_ptr?

If I understand correctly, a weak_ptr doesn't increment the reference count of the managed object, therefore it doesn't represent …

c++ shared-ptr smart-pointers unique-ptr weak-ptr