Top "Unique-ptr" questions

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

Move constructor involving const unique_ptr

In the code below, I made p const because it will never point to any other int during Foo's lifetime. …

c++ constants move unique-ptr move-constructor
std::unique_ptr vs std::shared_ptr vs std::weak_ptr vs std::auto_ptr vs raw pointers

What are the equivalent uses of each smart pointer in comparison to similar (but not limited to) some advanced techniques …

c++ shared-ptr unique-ptr auto-ptr weak-ptr
Why use std::make_unique in C++17?

As far as I understand, C++14 introduced std::make_unique because, as a result of the parameter evaluation order not …

c++ c++17 unique-ptr
Should std::unique_ptr<void> be permitted

This is a very simple question. Consider the following code: #include <iostream> #include <memory> typedef std::…

c++ visual-studio-2010 gcc c++11 unique-ptr
Can't use std::unique_ptr<T> with T being a forward declaration

Now first, I am aware of the general issues with unique_ptr<> and forward declarations as in Forward …

c++ c++11 unique-ptr forward-declaration
Converting std::unique_ptr<Derived> to std::unique_ptr<Base>

Using C++11, let's say I have factory functions dealing with base and derived classes: #include <memory> using namespace …

c++ c++11 unique-ptr c++14
C++ Arrays and make_unique

As a follow up to this post I wonder how its implementation of make_unique plays with allocating function-temporary buffer …

c++ arrays c++11 unique-ptr raii
Moving unique_ptrs from one vector to another

I'd like to move the unique_ptr's stored in an unsorted vector of them to another vector, that will contain …

c++ c++11 move-semantics unique-ptr
push_back or emplace_back with std::make_unique

Based on the answers in these questions here, I know that it is certainly preferred to use c++14's std::…

c++ c++11 stdvector c++14 unique-ptr
unique_ptr heap and stack allocation

Raw pointers can point to objects allocated on the stack or on the heap. Heap allocation example: // heap allocation int* …

c++11 pointers smart-pointers heap-memory unique-ptr