.TH "std::weak_ptr< _Tp >" 3cxx "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 "\fBusing\fP \fBelement_type\fP = \fBtypename\fP \fBremove_extent\fP< _Tp >::type" .br .in -1c .SS "Public Member Functions" .in +1c .ti -1c .RI "template<\fBtypename\fP \fB_Yp\fP , \fBtypename\fP = _Constructible&>> \fBweak_ptr\fP (const \fBshared_ptr\fP< \fB_Yp\fP > &__r) noexcept" .br .ti -1c .RI "\fBweak_ptr\fP (const \fBweak_ptr\fP &) noexcept=\fBdefault\fP" .br .ti -1c .RI "template<\fBtypename\fP \fB_Yp\fP , \fBtypename\fP = _Constructible&>> \fBweak_ptr\fP (const \fBweak_ptr\fP< \fB_Yp\fP > &__r) noexcept" .br .ti -1c .RI "\fBweak_ptr\fP (\fBweak_ptr\fP &&) noexcept=\fBdefault\fP" .br .ti -1c .RI "template<\fBtypename\fP \fB_Yp\fP , \fBtypename\fP = _Constructible>> \fBweak_ptr\fP (\fBweak_ptr\fP< \fB_Yp\fP > &&__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<\fBtypename\fP \fB_Yp\fP > _Assignable< const \fBshared_ptr\fP< \fB_Yp\fP > & > \fBoperator=\fP (const \fBshared_ptr\fP< \fB_Yp\fP > &__r) noexcept" .br .ti -1c .RI "\fBweak_ptr\fP & \fBoperator=\fP (const \fBweak_ptr\fP &__r) noexcept=\fBdefault\fP" .br .ti -1c .RI "template<\fBtypename\fP \fB_Yp\fP > _Assignable< const \fBweak_ptr\fP< \fB_Yp\fP > & > \fBoperator=\fP (const \fBweak_ptr\fP< \fB_Yp\fP > &__r) noexcept" .br .ti -1c .RI "\fBweak_ptr\fP & \fBoperator=\fP (\fBweak_ptr\fP &&__r) noexcept=\fBdefault\fP" .br .ti -1c .RI "template<\fBtypename\fP \fB_Yp\fP > _Assignable< \fBweak_ptr\fP< \fB_Yp\fP > > \fBoperator=\fP (\fBweak_ptr\fP< \fB_Yp\fP > &&__r) noexcept" .br .ti -1c .RI "template<\fBtypename\fP \fB_Tp1\fP > bool \fBowner_before\fP (const __shared_ptr< \fB_Tp1\fP, \fB_Lp\fP > &\fB__rhs\fP) const noexcept" .br .ti -1c .RI "template<\fBtypename\fP \fB_Tp1\fP > bool \fBowner_before\fP (const __weak_ptr< \fB_Tp1\fP, \fB_Lp\fP > &\fB__rhs\fP) const noexcept" .br .ti -1c .RI "\fBvoid\fP \fBreset\fP () noexcept" .br .ti -1c .RI "\fBvoid\fP \fBswap\fP (__weak_ptr &\fB__s\fP) noexcept" .br .ti -1c .RI "long \fBuse_count\fP () const noexcept" .br .in -1c .SS "Related Symbols" (Note that these are not member symbols\&.) .in +1c .ti -1c .RI "template<\fBtypename\fP _Tp > \fBvoid\fP \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<\fBtypename\fP _Tp> .br class std::weak_ptr< _Tp >"A non-owning observer for a pointer owned by a shared_ptr\&. .PP \fBSince\fP .RS 4 C++11 .RE .PP 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\&.