The
shared_ptr class template stores a pointer, usually obtained
via
new. shared_ptr implements semantics of shared ownership;
the last remaining owner of the pointer is responsible for destroying
the object, or otherwise releasing the resources associated with the stored pointer
. A
shared_ptr is said to be empty if it does not own a pointer
.namespace std {
template<class T> class shared_ptr {
public:
using element_type = remove_extent_t<T>;
using weak_type = weak_ptr<T>;
constexpr shared_ptr() noexcept;
constexpr shared_ptr(nullptr_t) noexcept : shared_ptr() { }
template<class Y>
explicit shared_ptr(Y* p);
template<class Y, class D>
shared_ptr(Y* p, D d);
template<class Y, class D, class A>
shared_ptr(Y* p, D d, A a);
template<class D>
shared_ptr(nullptr_t p, D d);
template<class D, class A>
shared_ptr(nullptr_t p, D d, A a);
template<class Y>
shared_ptr(const shared_ptr<Y>& r, element_type* p) noexcept;
template<class Y>
shared_ptr(shared_ptr<Y>&& r, element_type* p) noexcept;
shared_ptr(const shared_ptr& r) noexcept;
template<class Y>
shared_ptr(const shared_ptr<Y>& r) noexcept;
shared_ptr(shared_ptr&& r) noexcept;
template<class Y>
shared_ptr(shared_ptr<Y>&& r) noexcept;
template<class Y>
explicit shared_ptr(const weak_ptr<Y>& r);
template<class Y, class D>
shared_ptr(unique_ptr<Y, D>&& r);
~shared_ptr();
shared_ptr& operator=(const shared_ptr& r) noexcept;
template<class Y>
shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
shared_ptr& operator=(shared_ptr&& r) noexcept;
template<class Y>
shared_ptr& operator=(shared_ptr<Y>&& r) noexcept;
template<class Y, class D>
shared_ptr& operator=(unique_ptr<Y, D>&& r);
void swap(shared_ptr& r) noexcept;
void reset() noexcept;
template<class Y>
void reset(Y* p);
template<class Y, class D>
void reset(Y* p, D d);
template<class Y, class D, class A>
void reset(Y* p, D d, A a);
element_type* get() const noexcept;
T& operator*() const noexcept;
T* operator->() const noexcept;
element_type& operator[](ptrdiff_t i) const;
long use_count() const noexcept;
explicit operator bool() const noexcept;
template<class U>
bool owner_before(const shared_ptr<U>& b) const noexcept;
template<class U>
bool owner_before(const weak_ptr<U>& b) const noexcept;
};
template<class T>
shared_ptr(weak_ptr<T>) -> shared_ptr<T>;
template<class T, class D>
shared_ptr(unique_ptr<T, D>) -> shared_ptr<T>;
}