.TH "std::shared_ptr< _Tp >" 3cxx "Sun Jan 10 2021" "libstdc++" \" -*- nroff -*- .ad l .nh .SH NAME std::shared_ptr< _Tp > \- A smart pointer with reference-counted copy semantics\&. .SH SYNOPSIS .br .PP .PP Inherits std::__shared_ptr< _Tp, _Lp >\&. .SS "Public Types" .in +1c .ti -1c .RI "using \fBelement_type\fP = typename __shared_ptr< _Tp >::\fBelement_type\fP" .br .RI "The type pointed to by the stored pointer, remove_extent_t<_Tp> " .in -1c .SS "Public Member Functions" .in +1c .ti -1c .RI "constexpr \fBshared_ptr\fP () noexcept" .br .RI "Construct an empty shared_ptr\&. " .ti -1c .RI "template> \fBshared_ptr\fP (_Yp *__p)" .br .RI "Construct a shared_ptr that owns the pointer \fI__p\fP\&. " .ti -1c .RI "template> \fBshared_ptr\fP (_Yp *__p, _Deleter __d)" .br .RI "Construct a shared_ptr that owns the pointer \fI__p\fP and the deleter \fI__d\fP\&. " .ti -1c .RI "template> \fBshared_ptr\fP (_Yp *__p, _Deleter __d, _Alloc __a)" .br .RI "Construct a shared_ptr that owns the pointer \fI__p\fP and the deleter \fI__d\fP\&. " .ti -1c .RI "\fBshared_ptr\fP (const \fBshared_ptr\fP &) noexcept=default" .br .RI "Copy constructor\&. " .ti -1c .RI "template&>> \fBshared_ptr\fP (const \fBshared_ptr\fP< _Yp > &__r) noexcept" .br .RI "If \fI__r\fP is empty, constructs an empty shared_ptr; otherwise construct a shared_ptr that shares ownership with \fI__r\fP\&. " .ti -1c .RI "template \fBshared_ptr\fP (const \fBshared_ptr\fP< _Yp > &__r, \fBelement_type\fP *__p) noexcept" .br .RI "Constructs a \fCshared_ptr\fP instance that stores \fC__p\fP and shares ownership with \fC__r\fP\&. " .ti -1c .RI "template&>> \fBshared_ptr\fP (const \fBweak_ptr\fP< _Yp > &__r)" .br .RI "Constructs a shared_ptr that shares ownership with \fI__r\fP and stores a copy of the pointer stored in \fI__r\fP\&. " .ti -1c .RI "template \fBshared_ptr\fP (nullptr_t __p, _Deleter __d)" .br .RI "Construct a shared_ptr that owns a null pointer and the deleter \fI__d\fP\&. " .ti -1c .RI "template \fBshared_ptr\fP (nullptr_t __p, _Deleter __d, _Alloc __a)" .br .RI "Construct a shared_ptr that owns a null pointer and the deleter \fI__d\fP\&. " .ti -1c .RI "constexpr \fBshared_ptr\fP (nullptr_t) noexcept" .br .RI "Construct an empty shared_ptr\&. " .ti -1c .RI "\fBshared_ptr\fP (\fBshared_ptr\fP &&__r) noexcept" .br .RI "Move-constructs a shared_ptr instance from \fI__r\fP\&. " .ti -1c .RI "template>> \fBshared_ptr\fP (\fBshared_ptr\fP< _Yp > &&__r) noexcept" .br .RI "Move-constructs a shared_ptr instance from \fI__r\fP\&. " .ti -1c .RI "template \fBshared_ptr\fP (\fBstd::auto_ptr\fP< _Tp1 > &&__r)" .br .ti -1c .RI "template>> \fBshared_ptr\fP (\fBunique_ptr\fP< _Yp, _Del > &&__r)" .br .ti -1c .RI "\fBelement_type\fP * \fBget\fP () const noexcept" .br .RI "Return the stored pointer\&. " .ti -1c .RI "\fBoperator bool\fP () const" .br .RI "Return true if the stored pointer is not null\&. " .ti -1c .RI "\fBelement_type\fP & \fBoperator*\fP () const noexcept" .br .ti -1c .RI "\fBelement_type\fP * \fBoperator\->\fP () const noexcept" .br .ti -1c .RI "\fBshared_ptr\fP & \fBoperator=\fP (const \fBshared_ptr\fP &) noexcept=default" .br .ti -1c .RI "template _Assignable< const \fBshared_ptr\fP< _Yp > & > \fBoperator=\fP (const \fBshared_ptr\fP< _Yp > &__r) noexcept" .br .ti -1c .RI "\fBshared_ptr\fP & \fBoperator=\fP (\fBshared_ptr\fP &&__r) noexcept" .br .ti -1c .RI "template _Assignable< \fBshared_ptr\fP< _Yp > > \fBoperator=\fP (\fBshared_ptr\fP< _Yp > &&__r) noexcept" .br .ti -1c .RI "template _Assignable< \fBunique_ptr\fP< _Yp, _Del > > \fBoperator=\fP (\fBunique_ptr\fP< _Yp, _Del > &&__r)" .br .ti -1c .RI "void \fBreset\fP () noexcept" .br .ti -1c .RI "template _SafeConv< _Yp > \fBreset\fP (_Yp *__p)" .br .ti -1c .RI "template _SafeConv< _Yp > \fBreset\fP (_Yp *__p, _Deleter __d)" .br .ti -1c .RI "template _SafeConv< _Yp > \fBreset\fP (_Yp *__p, _Deleter __d, _Alloc __a)" .br .ti -1c .RI "void \fBswap\fP (__shared_ptr< _Tp, _Lp > &__other) noexcept" .br .RI "Exchange both the owned pointer and the stored pointer\&. " .ti -1c .RI "bool \fBunique\fP () const noexcept" .br .RI "Return true if use_count() == 1\&. " .ti -1c .RI "long \fBuse_count\fP () const noexcept" .br .RI "If *this owns a pointer, return the number of owners, otherwise zero\&. " .in -1c .PP .RI "\fB\fP" .br .in +1c .in +1c .ti -1c .RI "template bool \fBowner_before\fP (__shared_ptr< _Tp1, _Lp > const &__rhs) const noexcept" .br .RI "Define an ordering based on ownership\&. " .ti -1c .RI "template bool \fBowner_before\fP (__weak_ptr< _Tp1, _Lp > const &__rhs) const noexcept" .br .RI "Define an ordering based on ownership\&. " .in -1c .in -1c .SS "Friends" .in +1c .ti -1c .RI "template \fBshared_ptr\fP< _Yp > \fBallocate_shared\fP (const _Alloc &__a, _Args &&\&.\&.\&. __args)" .br .ti -1c .RI "class \fBweak_ptr< _Tp >\fP" .br .in -1c .SS "Related Functions" (Note that these are not member functions\&.) .in +1c .ti -1c .RI "template _Del * \fBget_deleter\fP (const \fBshared_ptr\fP< _Tp > &__p) noexcept" .br .RI "20\&.7\&.2\&.2\&.10 shared_ptr get_deleter " .ti -1c .RI "template \fBstd::basic_ostream\fP< _Ch, _Tr > & \fBoperator<<\fP (\fBstd::basic_ostream\fP< _Ch, _Tr > &__os, const __shared_ptr< _Tp, _Lp > &__p)" .br .RI "Write the stored pointer to an ostream\&. " .in -1c .PP .RI "\fB\fP" .br .in +1c .in +1c .ti -1c .RI "template bool \fBoperator==\fP (const \fBshared_ptr\fP< _Tp > &__a, const \fBshared_ptr\fP< _Up > &__b) noexcept" .br .ti -1c .RI "template bool \fBoperator==\fP (const \fBshared_ptr\fP< _Tp > &__a, nullptr_t) noexcept" .br .RI "shared_ptr comparison with nullptr " .ti -1c .RI "template bool \fBoperator==\fP (nullptr_t, const \fBshared_ptr\fP< _Tp > &__a) noexcept" .br .RI "shared_ptr comparison with nullptr " .ti -1c .RI "template bool \fBoperator!=\fP (const \fBshared_ptr\fP< _Tp > &__a, const \fBshared_ptr\fP< _Up > &__b) noexcept" .br .RI "Inequality operator for shared_ptr objects, compares the stored pointers\&. " .ti -1c .RI "template bool \fBoperator!=\fP (const \fBshared_ptr\fP< _Tp > &__a, nullptr_t) noexcept" .br .RI "shared_ptr comparison with nullptr " .ti -1c .RI "template bool \fBoperator!=\fP (nullptr_t, const \fBshared_ptr\fP< _Tp > &__a) noexcept" .br .RI "shared_ptr comparison with nullptr " .ti -1c .RI "template bool \fBoperator<\fP (const \fBshared_ptr\fP< _Tp > &__a, const \fBshared_ptr\fP< _Up > &__b) noexcept" .br .RI "Relational operator for shared_ptr objects, compares the stored pointers\&. " .ti -1c .RI "template bool \fBoperator<\fP (const \fBshared_ptr\fP< _Tp > &__a, nullptr_t) noexcept" .br .RI "shared_ptr comparison with nullptr " .ti -1c .RI "template bool \fBoperator<\fP (nullptr_t, const \fBshared_ptr\fP< _Tp > &__a) noexcept" .br .RI "shared_ptr comparison with nullptr " .ti -1c .RI "template bool \fBoperator<=\fP (const \fBshared_ptr\fP< _Tp > &__a, const \fBshared_ptr\fP< _Up > &__b) noexcept" .br .RI "Relational operator for shared_ptr objects, compares the stored pointers\&. " .ti -1c .RI "template bool \fBoperator<=\fP (const \fBshared_ptr\fP< _Tp > &__a, nullptr_t) noexcept" .br .RI "shared_ptr comparison with nullptr " .ti -1c .RI "template bool \fBoperator<=\fP (nullptr_t, const \fBshared_ptr\fP< _Tp > &__a) noexcept" .br .RI "shared_ptr comparison with nullptr " .ti -1c .RI "template bool \fBoperator>\fP (const \fBshared_ptr\fP< _Tp > &__a, const \fBshared_ptr\fP< _Up > &__b) noexcept" .br .RI "Relational operator for shared_ptr objects, compares the stored pointers\&. " .ti -1c .RI "template bool \fBoperator>\fP (const \fBshared_ptr\fP< _Tp > &__a, nullptr_t) noexcept" .br .RI "shared_ptr comparison with nullptr " .ti -1c .RI "template bool \fBoperator>\fP (nullptr_t, const \fBshared_ptr\fP< _Tp > &__a) noexcept" .br .RI "shared_ptr comparison with nullptr " .ti -1c .RI "template bool \fBoperator>=\fP (const \fBshared_ptr\fP< _Tp > &__a, const \fBshared_ptr\fP< _Up > &__b) noexcept" .br .RI "Relational operator for shared_ptr objects, compares the stored pointers\&. " .ti -1c .RI "template bool \fBoperator>=\fP (const \fBshared_ptr\fP< _Tp > &__a, nullptr_t) noexcept" .br .RI "shared_ptr comparison with nullptr " .ti -1c .RI "template bool \fBoperator>=\fP (nullptr_t, const \fBshared_ptr\fP< _Tp > &__a) noexcept" .br .RI "shared_ptr comparison with nullptr " .ti -1c .RI "template void \fBswap\fP (\fBshared_ptr\fP< _Tp > &__a, \fBshared_ptr\fP< _Tp > &__b) noexcept" .br .RI "Swap overload for shared_ptr\&. " .ti -1c .RI "template \fBshared_ptr\fP< _Tp > \fBstatic_pointer_cast\fP (const \fBshared_ptr\fP< _Up > &__r) noexcept" .br .RI "Convert type of \fCshared_ptr\fP, via \fCstatic_cast\fP " .ti -1c .RI "template \fBshared_ptr\fP< _Tp > \fBconst_pointer_cast\fP (const \fBshared_ptr\fP< _Up > &__r) noexcept" .br .RI "Convert type of \fCshared_ptr\fP, via \fCconst_cast\fP " .ti -1c .RI "template \fBshared_ptr\fP< _Tp > \fBdynamic_pointer_cast\fP (const \fBshared_ptr\fP< _Up > &__r) noexcept" .br .RI "Convert type of \fCshared_ptr\fP, via \fCdynamic_cast\fP " .ti -1c .RI "template \fBshared_ptr\fP< _Tp > \fBallocate_shared\fP (const _Alloc &__a, _Args &&\&.\&.\&. __args)" .br .RI "Create an object that is owned by a shared_ptr\&. " .ti -1c .RI "template \fBshared_ptr\fP< _Tp > \fBmake_shared\fP (_Args &&\&.\&.\&. __args)" .br .RI "Create an object that is owned by a shared_ptr\&. " .in -1c .in -1c .PP .RI "\fB\fP" .br .in +1c .in +1c .ti -1c .RI "template bool \fBatomic_is_lock_free\fP (const __shared_ptr< _Tp, _Lp > *__p)" .br .RI "Report whether shared_ptr atomic operations are lock-free\&. " .ti -1c .RI "template \fBshared_ptr\fP< _Tp > \fBatomic_load_explicit\fP (const \fBshared_ptr\fP< _Tp > *__p, \fBmemory_order\fP)" .br .RI "Atomic load for shared_ptr objects\&. " .ti -1c .RI "template void \fBatomic_store_explicit\fP (\fBshared_ptr\fP< _Tp > *__p, \fBshared_ptr\fP< _Tp > __r, \fBmemory_order\fP)" .br .RI "Atomic store for shared_ptr objects\&. " .ti -1c .RI "template \fBshared_ptr\fP< _Tp > \fBatomic_exchange_explicit\fP (\fBshared_ptr\fP< _Tp > *__p, \fBshared_ptr\fP< _Tp > __r, \fBmemory_order\fP)" .br .RI "Atomic exchange for shared_ptr objects\&. " .ti -1c .RI "template bool \fBatomic_compare_exchange_strong_explicit\fP (\fBshared_ptr\fP< _Tp > *__p, \fBshared_ptr\fP< _Tp > *__v, \fBshared_ptr\fP< _Tp > __w, \fBmemory_order\fP, \fBmemory_order\fP)" .br .RI "Atomic compare-and-swap for shared_ptr objects\&. " .in -1c .in -1c .SH "Detailed Description" .PP .SS "template .br class std::shared_ptr< _Tp >" A smart pointer with reference-counted copy semantics\&. A \fCshared_ptr\fP object is either empty or \fIowns\fP a pointer passed to the constructor\&. Copies of a \fCshared_ptr\fP share ownership of the same pointer\&. When the last \fCshared_ptr\fP that owns the pointer is destroyed or reset, the owned pointer is freed (either by \fCdelete\fP or by invoking a custom deleter that was passed to the constructor)\&. .PP A \fCshared_ptr\fP also stores another pointer, which is usually (but not always) the same pointer as it owns\&. The stored pointer can be retrieved by calling the \fCget()\fP member function\&. .PP The equality and relational operators for \fCshared_ptr\fP only compare the stored pointer returned by \fCget()\fP, not the owned pointer\&. To test whether two \fCshared_ptr\fP objects share ownership of the same pointer see \fCstd::shared_ptr::owner_before\fP and \fCstd::owner_less\fP\&. .PP Definition at line 121 of file bits/shared_ptr\&.h\&. .SH "Member Function Documentation" .PP .SS "template \fBelement_type\fP* std::__shared_ptr< _Tp, _Lp >::get (void) const\fC [inline]\fP, \fC [noexcept]\fP, \fC [inherited]\fP" .PP Return the stored pointer\&. .PP Definition at line 1324 of file shared_ptr_base\&.h\&. .SS "template std::__shared_ptr< _Tp, _Lp >::operator bool () const\fC [inline]\fP, \fC [explicit]\fP, \fC [inherited]\fP" .PP Return true if the stored pointer is not null\&. .PP Definition at line 1328 of file shared_ptr_base\&.h\&. .SS "template template bool std::__shared_ptr< _Tp, _Lp >::owner_before (__shared_ptr< _Tp1, _Lp > const & __rhs) const\fC [inline]\fP, \fC [noexcept]\fP, \fC [inherited]\fP" .PP Define an ordering based on ownership\&. This function defines a strict weak ordering between two shared_ptr or weak_ptr objects, such that one object is less than the other unless they share ownership of the same pointer, or are both empty\&. .PP Definition at line 1358 of file shared_ptr_base\&.h\&. .SS "template template bool std::__shared_ptr< _Tp, _Lp >::owner_before (__weak_ptr< _Tp1, _Lp > const & __rhs) const\fC [inline]\fP, \fC [noexcept]\fP, \fC [inherited]\fP" .PP Define an ordering based on ownership\&. This function defines a strict weak ordering between two shared_ptr or weak_ptr objects, such that one object is less than the other unless they share ownership of the same pointer, or are both empty\&. .PP Definition at line 1363 of file shared_ptr_base\&.h\&. .SS "template void std::__shared_ptr< _Tp, _Lp >::swap (__shared_ptr< _Tp, _Lp > & __other)\fC [inline]\fP, \fC [noexcept]\fP, \fC [inherited]\fP" .PP Exchange both the owned pointer and the stored pointer\&. .PP Definition at line 1343 of file shared_ptr_base\&.h\&. .SS "template bool std::__shared_ptr< _Tp, _Lp >::unique () const\fC [inline]\fP, \fC [noexcept]\fP, \fC [inherited]\fP" .PP Return true if use_count() == 1\&. .PP Definition at line 1333 of file shared_ptr_base\&.h\&. .SS "template long std::__shared_ptr< _Tp, _Lp >::use_count () const\fC [inline]\fP, \fC [noexcept]\fP, \fC [inherited]\fP" .PP If *this owns a pointer, return the number of owners, otherwise zero\&. .PP Definition at line 1338 of file shared_ptr_base\&.h\&. .SH "Author" .PP Generated automatically by Doxygen for libstdc++ from the source code\&.