[#bsl-weak_ptr-0d] = xref:bsl.adoc[bsl]::weak_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. == Synopsis Declared in `<bslstl_sharedptr.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class ELEMENT_TYPE> class weak_ptr; ---- == Type Aliases [cols="1,4"] |=== | Name| Description | xref:bsl/weak_ptr-0d/element_type.adoc[`element_type`] | For weak pointers to non‐array types, `element_type` is an alias to the `ELEMENT_TYPE` template parameter. Otherwise, it is an alias to the type contained in the array. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:bsl/weak_ptr-0d/2constructor-03.adoc[`weak_ptr`] [.small]#[constructor]# | Constructors | xref:bsl/weak_ptr-0d/2destructor.adoc[`~weak_ptr`] [.small]#[destructor]# | Destroy this weak pointer object. If this weak pointer manages a (possibly shared) object, release the weak reference to that object. | xref:bsl/weak_ptr-0d/operator_assign-09.adoc[`operator=`] | 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 == expired()`, and a shared pointer in the empty state otherwise. Note that the behavior of this method is the same as that of `lock`. | 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. | xref:bsl/weak_ptr-0d/lock.adoc[`lock`] | Return a shared pointer to the object referred to by this weak pointer if `false == expired()`, and a shared pointer in the empty state otherwise. | xref:bsl/weak_ptr-0d/numReferences.adoc[`numReferences`] | Return a "snapshot" 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. Note that the behavior of this method is the same as that of `use_count`, and the result may be unreliable in multi‐threaded code for the same reasons. | xref:bsl/weak_ptr-0d/owner_before-00.adoc[`owner_before`] | `owner_before` overloads | xref:bsl/weak_ptr-0d/owner_equal-02.adoc[`owner_equal`] | `owner_equal` overloads | xref:bsl/weak_ptr-0d/owner_hash.adoc[`owner_hash`] | Return an unspecified value such that, for any object `x` where `owner_equal(x)` is true, `owner_hash() == x.owner_hash()` is true. Note that this is based on the hash of the address of the `BloombergLP::bslma::SharedPtrRep` object used by this object. Note also that for two empty smart pointers `x` and `y`, `x.owner_hash() == y.owner_hash()` is true. | xref:bsl/weak_ptr-0d/rep.adoc[`rep`] | Return the address providing modifiable access to the `BloombergLP::bslma::SharedPtrRep` object held by this weak pointer, or 0 if this weak pointer is in the empty state. | xref:bsl/weak_ptr-0d/reset.adoc[`reset`] | Reset this weak pointer to the empty state. If this weak pointer manages a (possibly shared) object, then decrement the number of weak references to that object. | 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. | xref:bsl/weak_ptr-0d/use_count.adoc[`use_count`] | Return a "snapshot" 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. Note that any result other than 0 may be unreliable in a multi‐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). | xref:bsl/weak_ptr-0d/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<weak_ptr<ELEMENT_TYPE>, is_nothrow_move_constructible>`] | Nested trait declaration for `is_nothrow_move_constructible`. |=== == Deduction Guides [cols="1,4"] |=== | Name| Description | xref:bsl/weak_ptr-07.adoc[`weak_ptr<ELEMENT_TYPE>`] | Deduce the specified type `ELEMENT_TYPE` corresponding template parameter of the `bsl::shared_ptr` supplied to the constructor of `weak_ptr`. |=== == Friends [cols="1,4"] |=== | Name| Description | `bsl::weak_ptr` | This `friend` declaration provides access to the internal data members while constructing a weak pointer from a weak pointer of a different type. |=== == 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. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#