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>

template<class ELEMENT_TYPE>
class weak_ptr;

Type Aliases

Name

Description

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

Name

Description

weak_ptr [constructor]

Constructors

~weak_ptr [destructor]

Destroy this weak pointer object. If this weak pointer manages a (possibly shared) object, release the weak reference to that object.

operator=

Assignment operators

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.

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.

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.

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.

owner_before

owner_before overloads

owner_equal

owner_equal overloads

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.

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.

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.

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.

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).

operator BloombergLP::bslmf::NestedTraitDeclaration<weak_ptr<ELEMENT_TYPE>, is_nothrow_move_constructible>

Nested trait declaration for is_nothrow_move_constructible.

Deduction Guides

Name

Description

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

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

Name

Description

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.

Created with MrDocs