.TH "std::weak_ptr< _Tp >" 3cxx "Tue Jul 18 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\&. .SH "Author" .PP Generated automatically by Doxygen for libstdc++ from the source code\&.