.TH "std::weak_ptr< _Tp >" 3cxx "Thu Feb 16 2023" "libstdc++" \" -*- nroff -*- .ad l .nh .SH NAME std::weak_ptr< _Tp > \- A non-owning observer for a pointer owned by a shared_ptr\&. .SH SYNOPSIS .br .PP .PP \fC#include \fP .PP Inherits std::__weak_ptr< _Tp, _Lp >\&. .SS "Public Types" .in +1c .ti -1c .RI "using \fBelement_type\fP = typename \fBremove_extent\fP< _Tp >::type" .br .in -1c .SS "Public Member Functions" .in +1c .ti -1c .RI "template&>> \fBweak_ptr\fP (const \fBshared_ptr\fP< _Yp > &__r) noexcept" .br .ti -1c .RI "\fBweak_ptr\fP (const \fBweak_ptr\fP &) noexcept=default" .br .ti -1c .RI "template&>> \fBweak_ptr\fP (const \fBweak_ptr\fP< _Yp > &__r) noexcept" .br .ti -1c .RI "\fBweak_ptr\fP (\fBweak_ptr\fP &&) noexcept=default" .br .ti -1c .RI "template>> \fBweak_ptr\fP (\fBweak_ptr\fP< _Yp > &&__r) noexcept" .br .ti -1c .RI "bool \fBexpired\fP () const noexcept" .br .ti -1c .RI "\fBshared_ptr\fP< _Tp > \fBlock\fP () const noexcept" .br .ti -1c .RI "template _Assignable< const \fBshared_ptr\fP< _Yp > & > \fBoperator=\fP (const \fBshared_ptr\fP< _Yp > &__r) noexcept" .br .ti -1c .RI "\fBweak_ptr\fP & \fBoperator=\fP (const \fBweak_ptr\fP &__r) noexcept=default" .br .ti -1c .RI "template _Assignable< const \fBweak_ptr\fP< _Yp > & > \fBoperator=\fP (const \fBweak_ptr\fP< _Yp > &__r) noexcept" .br .ti -1c .RI "\fBweak_ptr\fP & \fBoperator=\fP (\fBweak_ptr\fP &&__r) noexcept=default" .br .ti -1c .RI "template _Assignable< \fBweak_ptr\fP< _Yp > > \fBoperator=\fP (\fBweak_ptr\fP< _Yp > &&__r) noexcept" .br .ti -1c .RI "template bool \fBowner_before\fP (const __shared_ptr< _Tp1, _Lp > &__rhs) const noexcept" .br .ti -1c .RI "template bool \fBowner_before\fP (const __weak_ptr< _Tp1, _Lp > &__rhs) const noexcept" .br .ti -1c .RI "void \fBreset\fP () noexcept" .br .ti -1c .RI "void \fBswap\fP (__weak_ptr &__s) noexcept" .br .ti -1c .RI "long \fBuse_count\fP () const noexcept" .br .in -1c .SS "Related Functions" (Note that these are not member functions\&.) .in +1c .ti -1c .RI "template void \fBswap\fP (\fBweak_ptr\fP< _Tp > &__a, \fBweak_ptr\fP< _Tp > &__b) noexcept" .br .RI "Swap overload for weak_ptr\&. " .in -1c .SH "Detailed Description" .PP .SS "template .br class std::weak_ptr< _Tp >"A non-owning observer for a pointer owned by a shared_ptr\&. A weak_ptr provides a safe alternative to a raw pointer when you want a non-owning reference to an object that is managed by a shared_ptr\&. .PP Unlike a raw pointer, a weak_ptr can be converted to a new shared_ptr that shares ownership with every other shared_ptr that already owns the pointer\&. In other words you can upgrade from a non-owning 'weak' reference to an owning shared_ptr, without having access to any of the existing shared_ptr objects\&. .PP Also unlike a raw pointer, a weak_ptr does not become 'dangling' after the object it points to has been destroyed\&. Instead, a weak_ptr becomes \fIexpired\fP and can no longer be converted to a shared_ptr that owns the freed pointer, so you cannot accidentally access the pointed-to object after it has been destroyed\&. .PP Definition at line \fB686\fP of file \fBbits/shared_ptr\&.h\fP\&. .SH "Member Typedef Documentation" .PP .SS "template using std::__weak_ptr< _Tp, _Lp >::element_type = typename \fBremove_extent\fP<_Tp>::type\fC [inherited]\fP" .PP Definition at line \fB1602\fP of file \fBshared_ptr_base\&.h\fP\&. .SH "Constructor & Destructor Documentation" .PP .SS "template template&>> \fBstd::weak_ptr\fP< _Tp >::weak_ptr (const \fBshared_ptr\fP< _Yp > & __r)\fC [inline]\fP, \fC [noexcept]\fP" .PP Definition at line \fB703\fP of file \fBbits/shared_ptr\&.h\fP\&. .SS "template template&>> \fBstd::weak_ptr\fP< _Tp >::weak_ptr (const \fBweak_ptr\fP< _Yp > & __r)\fC [inline]\fP, \fC [noexcept]\fP" .PP Definition at line \fB709\fP of file \fBbits/shared_ptr\&.h\fP\&. .SS "template template>> \fBstd::weak_ptr\fP< _Tp >::weak_ptr (\fBweak_ptr\fP< _Yp > && __r)\fC [inline]\fP, \fC [noexcept]\fP" .PP Definition at line \fB715\fP of file \fBbits/shared_ptr\&.h\fP\&. .SH "Member Function Documentation" .PP .SS "template bool std::__weak_ptr< _Tp, _Lp >::expired () const\fC [inline]\fP, \fC [noexcept]\fP, \fC [inherited]\fP" .PP Definition at line \fB1694\fP of file \fBshared_ptr_base\&.h\fP\&. .SS "template \fBshared_ptr\fP< _Tp > \fBstd::weak_ptr\fP< _Tp >::lock () const\fC [inline]\fP, \fC [noexcept]\fP" .PP Definition at line \fB749\fP of file \fBbits/shared_ptr\&.h\fP\&. .SS "template template _Assignable< const \fBshared_ptr\fP< _Yp > & > \fBstd::weak_ptr\fP< _Tp >::operator= (const \fBshared_ptr\fP< _Yp > & __r)\fC [inline]\fP, \fC [noexcept]\fP" .PP Definition at line \fB731\fP of file \fBbits/shared_ptr\&.h\fP\&. .SS "template template _Assignable< const \fBweak_ptr\fP< _Yp > & > \fBstd::weak_ptr\fP< _Tp >::operator= (const \fBweak_ptr\fP< _Yp > & __r)\fC [inline]\fP, \fC [noexcept]\fP" .PP Definition at line \fB723\fP of file \fBbits/shared_ptr\&.h\fP\&. .SS "template template _Assignable< \fBweak_ptr\fP< _Yp > > \fBstd::weak_ptr\fP< _Tp >::operator= (\fBweak_ptr\fP< _Yp > && __r)\fC [inline]\fP, \fC [noexcept]\fP" .PP Definition at line \fB742\fP of file \fBbits/shared_ptr\&.h\fP\&. .SS "template template bool std::__weak_ptr< _Tp, _Lp >::owner_before (const __shared_ptr< _Tp1, _Lp > & __rhs) const\fC [inline]\fP, \fC [noexcept]\fP, \fC [inherited]\fP" .PP Definition at line \fB1699\fP of file \fBshared_ptr_base\&.h\fP\&. .SS "template template bool std::__weak_ptr< _Tp, _Lp >::owner_before (const __weak_ptr< _Tp1, _Lp > & __rhs) const\fC [inline]\fP, \fC [noexcept]\fP, \fC [inherited]\fP" .PP Definition at line \fB1704\fP of file \fBshared_ptr_base\&.h\fP\&. .SS "template void std::__weak_ptr< _Tp, _Lp >::reset ()\fC [inline]\fP, \fC [noexcept]\fP, \fC [inherited]\fP" .PP Definition at line \fB1708\fP of file \fBshared_ptr_base\&.h\fP\&. .SS "template void std::__weak_ptr< _Tp, _Lp >::swap (__weak_ptr< _Tp, _Lp > & __s)\fC [inline]\fP, \fC [noexcept]\fP, \fC [inherited]\fP" .PP Definition at line \fB1712\fP of file \fBshared_ptr_base\&.h\fP\&. .SS "template long std::__weak_ptr< _Tp, _Lp >::use_count () const\fC [inline]\fP, \fC [noexcept]\fP, \fC [inherited]\fP" .PP Definition at line \fB1690\fP of file \fBshared_ptr_base\&.h\fP\&. .SH "Author" .PP Generated automatically by Doxygen for libstdc++ from the source code\&.