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);

Precondition:

Target* is implicitly convertible to T*.

Effects:

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.

Postconditions:

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.

Throws:

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

Header

#include <experimental/atomic>

See Also