Documentation Home >> Headers >> <jss/experimental_atomic.hpp> Header >> std::experimental::shared_ptr >> std::experimental::shared_ptr constructor from std::unique_ptr

Move-constructs a new std::experimental::shared_ptr object from a std::unique_ptr instance with a different pointer type.

template<class Target,class Deleter>
explicit shared_ptr(unique_ptr<Target,Deleter>&& p);


Target* is implicitly convertible to T*.


Transfers ownership of the pointer from p to the newly constructed std::experimental::shared_ptr instance; the newly-constructed std::experimental::shared_ptr holds a copy of the Deleter from the p, which will be used to destroy the owned pointer when the last std::experimental::shared_ptr instance is destroyed or reassigned.


this->unique(). this->get() has the value static_cast<T*>(p.get()) had before the constructor was invoked. get_deleter<Deleter>(*this) returns a pointer to the deleter owned by p. p.get()==0.


std::bad_alloc if memory could not be allocated for the internal control block.


#include <experimental/atomic>

See Also