[#bsl-weak_ptr-0d]
= xref:bsl.adoc[bsl]::weak&lowbar;ptr
:relfileprefix: ../
:mrdocs:

This `friend` declaration provides access to the internal data members while constructing a weak pointer from a weak pointer of a different type&period;

== Synopsis

Declared in `&lt;bslstl&lowbar;sharedptr&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class ELEMENT&lowbar;TYPE&gt;
class weak&lowbar;ptr;
----

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:bsl/weak_ptr-0d/element_type.adoc[`element&lowbar;type`] 
| For weak pointers to non&hyphen;array types, `element&lowbar;type` is an alias to the `ELEMENT&lowbar;TYPE` template parameter&period; Otherwise, it is an alias to the type contained in the array&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/weak_ptr-0d/2constructor-03.adoc[`weak&lowbar;ptr`]         [.small]#[constructor]#
| Constructors
| xref:bsl/weak_ptr-0d/2destructor.adoc[`&#126;weak&lowbar;ptr`] [.small]#[destructor]#
| Destroy this weak pointer object&period; If this weak pointer manages a (possibly shared) object, release the weak reference to that object&period;
| xref:bsl/weak_ptr-0d/operator_assign-09.adoc[`operator&equals;`] 
| Assignment operators
| xref:bsl/weak_ptr-0d/acquireSharedPtr.adoc[`acquireSharedPtr`] 
| Return a shared pointer to the object referred to by this weak pointer and managing the same object as that managed by this weak pointer (if any) if `false &equals;&equals; expired()`, and a shared pointer in the empty state otherwise&period; Note that the behavior of this method is the same as that of `lock`&period;
| xref:bsl/weak_ptr-0d/expired.adoc[`expired`] 
| Return `true` if this weak pointer is in the empty state or the object that it originally referenced has been destroyed, and `false` otherwise&period;
| xref:bsl/weak_ptr-0d/lock.adoc[`lock`] 
| Return a shared pointer to the object referred to by this weak pointer if `false &equals;&equals; expired()`, and a shared pointer in the empty state otherwise&period;
| xref:bsl/weak_ptr-0d/numReferences.adoc[`numReferences`] 
| Return a &quot;snapshot&quot; of the current number of shared pointers that share ownership of the object referred to by this weak pointer, or 0 if this weak pointer is in the empty state&period; Note that the behavior of this method is the same as that of `use&lowbar;count`, and the result may be unreliable in multi&hyphen;threaded code for the same reasons&period;
| xref:bsl/weak_ptr-0d/owner_before-00.adoc[`owner&lowbar;before`] 
| `owner&lowbar;before` overloads
| xref:bsl/weak_ptr-0d/owner_equal-02.adoc[`owner&lowbar;equal`] 
| `owner&lowbar;equal` overloads
| xref:bsl/weak_ptr-0d/owner_hash.adoc[`owner&lowbar;hash`] 
| Return an unspecified value such that, for any object `x` where `owner&lowbar;equal(x)` is true, `owner&lowbar;hash() &equals;&equals; x&period;owner&lowbar;hash()` is true&period; Note that this is based on the hash of the address of the `BloombergLP&colon;&colon;bslma&colon;&colon;SharedPtrRep` object used by this object&period; Note also that for two empty smart pointers `x` and `y`, `x&period;owner&lowbar;hash() &equals;&equals; y&period;owner&lowbar;hash()` is true&period;
| xref:bsl/weak_ptr-0d/rep.adoc[`rep`] 
| Return the address providing modifiable access to the `BloombergLP&colon;&colon;bslma&colon;&colon;SharedPtrRep` object held by this weak pointer, or 0 if this weak pointer is in the empty state&period;
| xref:bsl/weak_ptr-0d/reset.adoc[`reset`] 
| Reset this weak pointer to the empty state&period; If this weak pointer manages a (possibly shared) object, then decrement the number of weak references to that object&period;
| xref:bsl/weak_ptr-0d/swap.adoc[`swap`] 
| Efficiently exchange the states of this weak pointer and the specified `other` weak pointer such that each will refer to the object (if any) and representation (if any) formerly referred to and managed by the other&period;
| xref:bsl/weak_ptr-0d/use_count.adoc[`use&lowbar;count`] 
| Return a &quot;snapshot&quot; of the current number of shared pointers that share ownership of the object referred to by this weak pointer, or 0 if this weak pointer is in the empty state&period; Note that any result other than 0 may be unreliable in a multi&hyphen;threaded program, where another pointer sharing ownership in a different thread may be copied or destroyed, or another weak pointer may be locked in the case that 1 is returned (that would otherwise indicate unique ownership)&period;
| xref:bsl/weak_ptr-0d/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;weak&lowbar;ptr&lt;ELEMENT&lowbar;TYPE&gt;, is&lowbar;nothrow&lowbar;move&lowbar;constructible&gt;`] 
| Nested trait declaration for `is&lowbar;nothrow&lowbar;move&lowbar;constructible`&period;
|===


== Deduction Guides

[cols="1,4"]
|===
| Name| Description
| xref:bsl/weak_ptr-07.adoc[`weak&lowbar;ptr&lt;ELEMENT&lowbar;TYPE&gt;`] 
| Deduce the specified type `ELEMENT&lowbar;TYPE` corresponding template parameter of the `bsl&colon;&colon;shared&lowbar;ptr` supplied to the constructor of `weak&lowbar;ptr`&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `bsl::weak&lowbar;ptr`
| This `friend` declaration provides access to the internal data members while constructing a weak pointer from a weak pointer of a different type&period;
|===

== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/swap-0447.adoc[`swap`]
| Efficiently exchange the states of the specified `a` and `b` weak pointers such that each will refer to the object (if any) and representation formerly referred to by the other&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
