.TH "std::shared_ptr< _Tp >" 3cxx "Fri May 28 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 >::element_type" .br .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 .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, element_type *__p) noexcept" .br .RI "Constructs a shared_ptr instance that stores \fI__p\fP and shares ownership with \fI__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 "element_type * \fBget\fP () const noexcept" .br .ti -1c .RI "\fBoperator bool\fP () const" .br .ti -1c .RI "element_type & \fBoperator*\fP () const noexcept" .br .ti -1c .RI "element_type * \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 "template bool \fBowner_before\fP (__shared_ptr< _Tp1, _Lp > const &__rhs) const noexcept" .br .ti -1c .RI "template bool \fBowner_before\fP (__weak_ptr< _Tp1, _Lp > const &__rhs) const noexcept" .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 .ti -1c .RI "bool \fBunique\fP () const noexcept" .br .ti -1c .RI "long \fBuse_count\fP () const noexcept" .br .in -1c .SS "Friends" .in +1c .ti -1c .RI "template \fBshared_ptr\fP< _Yp > \fBallocate_shared\fP (const _Alloc &__a, _Args &&\&.\&.\&. __args)" .br .RI "Create an object that is owned by a shared_ptr\&. " .ti -1c .RI "class \fBweak_ptr< _Tp >\fP" .br .in -1c .SH "Detailed Description" .PP .SS "template .br class std::shared_ptr< _Tp >" A smart pointer with reference-counted copy semantics\&. The object pointed to is deleted when the last shared_ptr pointing to it is destroyed or reset\&. .PP Definition at line 103 of file bits/shared_ptr\&.h\&. .SH "Constructor & Destructor Documentation" .PP .SS "template constexpr \fBstd::shared_ptr\fP< _Tp >::\fBshared_ptr\fP ()\fC [inline]\fP, \fC [constexpr]\fP, \fC [noexcept]\fP" .PP Construct an empty shared_ptr\&. .PP \fBPostcondition\fP .RS 4 use_count()==0 && get()==0 .RE .PP .PP Definition at line 127 of file bits/shared_ptr\&.h\&. .SS "template template> \fBstd::shared_ptr\fP< _Tp >::\fBshared_ptr\fP (_Yp * __p)\fC [inline]\fP, \fC [explicit]\fP" .PP Construct a shared_ptr that owns the pointer \fI__p\fP\&. .PP \fBParameters\fP .RS 4 \fI__p\fP A pointer that is convertible to element_type*\&. .RE .PP \fBPostcondition\fP .RS 4 use_count() == 1 && get() == __p .RE .PP \fBExceptions\fP .RS 4 \fIstd::bad_alloc,in\fP which case \fCdelete\fP \fI__p\fP is called\&. .RE .PP .PP Definition at line 139 of file bits/shared_ptr\&.h\&. .SS "template template> \fBstd::shared_ptr\fP< _Tp >::\fBshared_ptr\fP (_Yp * __p, _Deleter __d)\fC [inline]\fP" .PP Construct a shared_ptr that owns the pointer \fI__p\fP and the deleter \fI__d\fP\&. .PP \fBParameters\fP .RS 4 \fI__p\fP A pointer\&. .br \fI__d\fP A deleter\&. .RE .PP \fBPostcondition\fP .RS 4 use_count() == 1 && get() == __p .RE .PP \fBExceptions\fP .RS 4 \fIstd::bad_alloc,in\fP which case \fI__d(__p)\fP is called\&. .RE .PP Requirements: _Deleter's copy constructor and destructor must not throw .PP __shared_ptr will release __p by calling __d(__p) .PP Definition at line 156 of file bits/shared_ptr\&.h\&. .SS "template template \fBstd::shared_ptr\fP< _Tp >::\fBshared_ptr\fP (nullptr_t __p, _Deleter __d)\fC [inline]\fP" .PP Construct a shared_ptr that owns a null pointer and the deleter \fI__d\fP\&. .PP \fBParameters\fP .RS 4 \fI__p\fP A null pointer constant\&. .br \fI__d\fP A deleter\&. .RE .PP \fBPostcondition\fP .RS 4 use_count() == 1 && get() == __p .RE .PP \fBExceptions\fP .RS 4 \fIstd::bad_alloc,in\fP which case \fI__d(__p)\fP is called\&. .RE .PP Requirements: _Deleter's copy constructor and destructor must not throw .PP The last owner will call __d(__p) .PP Definition at line 173 of file bits/shared_ptr\&.h\&. .SS "template template> \fBstd::shared_ptr\fP< _Tp >::\fBshared_ptr\fP (_Yp * __p, _Deleter __d, _Alloc __a)\fC [inline]\fP" .PP Construct a shared_ptr that owns the pointer \fI__p\fP and the deleter \fI__d\fP\&. .PP \fBParameters\fP .RS 4 \fI__p\fP A pointer\&. .br \fI__d\fP A deleter\&. .br \fI__a\fP An allocator\&. .RE .PP \fBPostcondition\fP .RS 4 use_count() == 1 && get() == __p .RE .PP \fBExceptions\fP .RS 4 \fIstd::bad_alloc,in\fP which case \fI__d(__p)\fP is called\&. .RE .PP Requirements: _Deleter's copy constructor and destructor must not throw _Alloc's copy constructor and destructor must not throw\&. .PP __shared_ptr will release __p by calling __d(__p) .PP Definition at line 193 of file bits/shared_ptr\&.h\&. .SS "template template \fBstd::shared_ptr\fP< _Tp >::\fBshared_ptr\fP (nullptr_t __p, _Deleter __d, _Alloc __a)\fC [inline]\fP" .PP Construct a shared_ptr that owns a null pointer and the deleter \fI__d\fP\&. .PP \fBParameters\fP .RS 4 \fI__p\fP A null pointer constant\&. .br \fI__d\fP A deleter\&. .br \fI__a\fP An allocator\&. .RE .PP \fBPostcondition\fP .RS 4 use_count() == 1 && get() == __p .RE .PP \fBExceptions\fP .RS 4 \fIstd::bad_alloc,in\fP which case \fI__d(__p)\fP is called\&. .RE .PP Requirements: _Deleter's copy constructor and destructor must not throw _Alloc's copy constructor and destructor must not throw\&. .PP The last owner will call __d(__p) .PP Definition at line 212 of file bits/shared_ptr\&.h\&. .SS "template template \fBstd::shared_ptr\fP< _Tp >::\fBshared_ptr\fP (const \fBshared_ptr\fP< _Yp > & __r, element_type * __p)\fC [inline]\fP, \fC [noexcept]\fP" .PP Constructs a shared_ptr instance that stores \fI__p\fP and shares ownership with \fI__r\fP\&. .PP \fBParameters\fP .RS 4 \fI__r\fP A shared_ptr\&. .br \fI__p\fP A pointer that will remain valid while \fI*__r\fP is valid\&. .RE .PP \fBPostcondition\fP .RS 4 get() == __p && use_count() == __r\&.use_count() .RE .PP This can be used to construct a \fCshared_ptr\fP to a sub-object of an object managed by an existing \fCshared_ptr\fP\&. .PP .PP .nf shared_ptr< pair > pii(new pair()); shared_ptr pi(pii, &pii->first); assert(pii\&.use_count() == 2); .fi .PP .PP Definition at line 234 of file bits/shared_ptr\&.h\&. .SS "template template&>> \fBstd::shared_ptr\fP< _Tp >::\fBshared_ptr\fP (const \fBshared_ptr\fP< _Yp > & __r)\fC [inline]\fP, \fC [noexcept]\fP" .PP If \fI__r\fP is empty, constructs an empty shared_ptr; otherwise construct a shared_ptr that shares ownership with \fI__r\fP\&. .PP \fBParameters\fP .RS 4 \fI__r\fP A shared_ptr\&. .RE .PP \fBPostcondition\fP .RS 4 get() == __r\&.get() && use_count() == __r\&.use_count() .RE .PP .PP Definition at line 246 of file bits/shared_ptr\&.h\&. .SS "template \fBstd::shared_ptr\fP< _Tp >::\fBshared_ptr\fP (\fBshared_ptr\fP< _Tp > && __r)\fC [inline]\fP, \fC [noexcept]\fP" .PP Move-constructs a shared_ptr instance from \fI__r\fP\&. .PP \fBParameters\fP .RS 4 \fI__r\fP A shared_ptr rvalue\&. .RE .PP \fBPostcondition\fP .RS 4 *this contains the old value of \fI__r\fP, \fI__r\fP is empty\&. .RE .PP .PP Definition at line 254 of file bits/shared_ptr\&.h\&. .SS "template template>> \fBstd::shared_ptr\fP< _Tp >::\fBshared_ptr\fP (\fBshared_ptr\fP< _Yp > && __r)\fC [inline]\fP, \fC [noexcept]\fP" .PP Move-constructs a shared_ptr instance from \fI__r\fP\&. .PP \fBParameters\fP .RS 4 \fI__r\fP A shared_ptr rvalue\&. .RE .PP \fBPostcondition\fP .RS 4 *this contains the old value of \fI__r\fP, \fI__r\fP is empty\&. .RE .PP .PP Definition at line 263 of file bits/shared_ptr\&.h\&. .SS "template template&>> \fBstd::shared_ptr\fP< _Tp >::\fBshared_ptr\fP (const \fBweak_ptr\fP< _Yp > & __r)\fC [inline]\fP, \fC [explicit]\fP" .PP Constructs a shared_ptr that shares ownership with \fI__r\fP and stores a copy of the pointer stored in \fI__r\fP\&. .PP \fBParameters\fP .RS 4 \fI__r\fP A weak_ptr\&. .RE .PP \fBPostcondition\fP .RS 4 use_count() == __r\&.use_count() .RE .PP \fBExceptions\fP .RS 4 \fIbad_weak_ptr\fP when __r\&.expired(), in which case the constructor has no effect\&. .RE .PP .PP Definition at line 275 of file bits/shared_ptr\&.h\&. .SS "template constexpr \fBstd::shared_ptr\fP< _Tp >::\fBshared_ptr\fP (nullptr_t)\fC [inline]\fP, \fC [constexpr]\fP, \fC [noexcept]\fP" .PP Construct an empty shared_ptr\&. .PP \fBPostcondition\fP .RS 4 use_count() == 0 && get() == nullptr .RE .PP .PP Definition at line 307 of file bits/shared_ptr\&.h\&. .SH "Friends And Related Function Documentation" .PP .SS "template template \fBshared_ptr\fP<_Yp> allocate_shared (const _Alloc & __a, _Args &&\&.\&.\&. __args)\fC [friend]\fP" .PP Create an object that is owned by a shared_ptr\&. .PP \fBParameters\fP .RS 4 \fI__a\fP An allocator\&. .br \fI__args\fP Arguments for the \fI_Tp\fP object's constructor\&. .RE .PP \fBReturns\fP .RS 4 A shared_ptr that owns the newly created object\&. .RE .PP \fBExceptions\fP .RS 4 \fIAn\fP exception thrown from \fI_Alloc::allocate\fP or from the constructor of \fI_Tp\fP\&. .RE .PP A copy of \fI__a\fP will be used to allocate memory for the shared_ptr and the new object\&. .PP Definition at line 699 of file bits/shared_ptr\&.h\&. .SH "Author" .PP Generated automatically by Doxygen for libstdc++ from the source code\&.