[#bsl-shared_ptr-0a] = xref:bsl.adoc[bsl]::shared_ptr :relfileprefix: ../ :mrdocs: This class provides a thread‐safe reference‐counted "smart pointer" to support "shared ownership" of objects: a shared pointer ensures that the shared object is destroyed, using the appropriate deletion method, only when there are no shared references to it. The object (of template parameter type `ELEMENT_TYPE`) referred to by a shared pointer may be accessed directly using the `‐>` operator, or the dereference operator (operator `*`) can be used to obtain a reference to that object. == Synopsis Declared in `<bslstl_sharedptr.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class ELEMENT_TYPE> class shared_ptr; ---- == Description Note that the object referred to by a shared pointer representation is usually the same as the object referred to by that shared pointer (of the same `ELEMENT_TYPE`), but this need not always be true in the presence of conversions or "aliasing": the object referred to (of template parameter type `ELEMENT_TYPE`) by the shared pointer may differ from the object of type `COMPATIBLE_TYPE` (see the "Aliasing" section in the component‐level documentation) referred to by the shared pointer representation. More generally, this class supports a complete set of _in_‐_core_ pointer semantic operations. == Type Aliases [cols="1,4"] |=== | Name| Description | xref:bsl/shared_ptr-0a/element_type.adoc[`element_type`] | For shared 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. | xref:bsl/shared_ptr-0a/weak_type.adoc[`weak_type`] | `weak_type` is an alias to a weak pointer with the same element type as this `shared_ptr`. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:bsl/shared_ptr-0a/2constructor-03f.adoc[`shared_ptr`] [.small]#[constructor]# | Constructors | xref:bsl/shared_ptr-0a/2destructor.adoc[`~shared_ptr`] [.small]#[destructor]# | Destroy this shared pointer. If this shared pointer refers to a (possibly shared) object, then release the reference to that object, and destroy the shared object using its associated deleter if this shared pointer is the last reference to that object. | xref:bsl/shared_ptr-0a/operator_assign-05.adoc[`operator=`] | Assignment operators | xref:bsl/shared_ptr-0a/clear.adoc[`clear`] | Reset this shared pointer to the empty state. If this shared pointer is managing a (possibly shared) object, then release the reference to the shared object, calling the associated deleter to destroy the shared object if this shared pointer is the last reference. Note that the behavior of this method is the same as `reset()`. | xref:bsl/shared_ptr-0a/createInplace-00.adoc[`createInplace`] | `createInplace` overloads | xref:bsl/shared_ptr-0a/get.adoc[`get`] | Return the address providing modifiable access to the object referred to by this shared pointer, or 0 if this shared pointer does not refer to an object. | xref:bsl/shared_ptr-0a/load-06.adoc[`load`] | `load` overloads | xref:bsl/shared_ptr-0a/loadAlias.adoc[`loadAlias`] | Modify this shared pointer to manage the same modifiable object (if any) as the specified `source` shared pointer to the (template parameter) type `ANY_TYPE`, and refer to the modifiable object at the specified `object` address (i.e., make this shared pointer an "alias" of `source`). If this shared pointer is already managing a (possibly shared) object, then release the shared reference to that shared object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object. Note that typically the objects referred to by `source` and `object` have identical lifetimes (e.g., one might be a part of the other), so that the deleter for `source` will destroy them both, but they do not necessarily have the same type. Also note that if `source` is empty, then this shared pointer will be reset to an empty state, even if `object` is not null (in which case this empty shared pointer will refer to the same object as `object`). Also note that if `object` is null and `source` is not empty, then this shared pointer will be reset to a (reference‐counted) null pointer alias. Also note that this function is logically equivalent to: ` *this = shared_ptr<ELEMENT_TYPE>(source, object); ` Further note that the behavior of this method is the same as `reset(source, object)`. | xref:bsl/shared_ptr-0a/managedPtr.adoc[`managedPtr`] | Return a managed pointer that refers to the same object as this shared pointer. If this shared pointer is not empty, and is not null, then increment the shared count on the shared object, and give the managed pointer a deleter that decrements the reference count for the shared object. Note that if this `shared_ptr` is reference‐ counting a null pointer, the empty `bslma::ManagedPtr` returned will not participate in that shared ownership. | xref:bsl/shared_ptr-0a/numReferences.adoc[`numReferences`] | Return a "snapshot" of the number of shared pointers (including this one) that share ownership of the object managed by this shared pointer. Note that the behavior of this function is the same as `use_count`, and the result may be unreliable in multi‐threaded code for the same reasons. | xref:bsl/shared_ptr-0a/operator_star.adoc[`operator*`] | Return a reference providing modifiable access to the object referred to by this shared pointer. The behavior is undefined unless this shared pointer refers to an object, and `ELEMENT_TYPE` is not (potentially `const` or `volatile` qualified) `void`. | xref:bsl/shared_ptr-0a/operator_ptr.adoc[`operator‐>`] | Return the address providing modifiable access to the object referred to by this shared pointer, or 0 if this shared pointer does not refer to an object. Note that applying this operator conventionally (e.g., to invoke a method) to an shared pointer that does not refer to an object will result in undefined behavior. | xref:bsl/shared_ptr-0a/operator_subs.adoc[`operator[]`] | Return a reference providing modifiable access to the object at the specified `index` offset in the object referred to by this shared pointer. The behavior is undefined unless this shared pointer is not empty, `ELEMENT_TYPE` is not `void` (a compiler error will be generated if this operator is instantiated within the `shared_ptr<void>` class), and this shared pointer refers to an array of `ELEMENT_TYPE` objects. Instead of `element_type &`, we use `add_lvalue_reference<element_type>::type` for the return type because that allows people to instantiate `shared_ptr<cv_void>`, as long as they don't use this method. Note that this method is logically equivalent to `*(get() + index)`. | xref:bsl/shared_ptr-0a/owner_before-0f.adoc[`owner_before`] | `owner_before` overloads | xref:bsl/shared_ptr-0a/owner_equal-08.adoc[`owner_equal`] | `owner_equal` overloads | xref:bsl/shared_ptr-0a/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/shared_ptr-0a/ptr.adoc[`ptr`] | Return the address providing modifiable access to the object referred to by this shared pointer, or 0 if this shared pointer does not refer to an object. Note that the behavior of this function is the same as `get`. | xref:bsl/shared_ptr-0a/release.adoc[`release`] | Return the pair consisting of the addresses of the modifiable `ELEMENT_TYPE` object referred to, and the representation shared by, this shared pointer, and reset this shared pointer to the empty state, referring to no object, with no effect on the representation. The reference counter is not modified nor is the shared object deleted; if the reference count of the representation is greater than one, then it is not safe to release the representation (thereby destroying the shared object), but it is always safe to create another shared pointer with the representation using the constructor with the following signature: ` 'shared_ptr(ELEMENT_TYPE *ptr, BloombergLP::bslma::SharedPtrRep *rep)' ` Note that this function returns a pair of null pointers if this shared pointer is empty. | xref:bsl/shared_ptr-0a/rep.adoc[`rep`] | Return the address providing modifiable access to the `BloombergLP::bslma::SharedPtrRep` object used by this shared pointer, or 0 if this shared pointer is empty. | xref:bsl/shared_ptr-0a/reset-0c8.adoc[`reset`] | `reset` overloads | xref:bsl/shared_ptr-0a/swap.adoc[`swap`] | Efficiently exchange the states of this shared pointer and the specified `other` shared pointer such that each will refer to the object formerly referred to by the other and each will manage the object formerly managed by the other. | xref:bsl/shared_ptr-0a/unique.adoc[`unique`] | Return `true` if this shared pointer is not empty and does not share ownership of the object it managed with any other shared pointer, and `false` otherwise. Note that a shared pointer with a custom deleter can refer to a null pointer without being empty, and so may be `unique`. Also note that the result of this function may not be reliable in a multi‐threaded program, where a weak pointer may be locked on another thread. | xref:bsl/shared_ptr-0a/use_count.adoc[`use_count`] | Return a "snapshot" of the number of shared pointers (including this one) that share ownership of the object managed by this shared pointer. Note that 0 is returned if this shared pointer is empty. Also 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 a weak pointer may be locked in the case that 1 is returned (that would otherwise indicate unique ownership). | xref:bsl/shared_ptr-0a/2conversion-01.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<shared_ptr<ELEMENT_TYPE>, is_nothrow_move_constructible>`] | Nested trait declaration for `is_nothrow_move_constructible`. | xref:bsl/shared_ptr-0a/2conversion-05.adoc[`operator BoolType`] | Return a value of an "unspecified bool" type that evaluates to `false` if this shared pointer does not refer to an object, and `true` otherwise. Note that this conversion operator allows a shared pointer to be used within a conditional context (e.g., within an `if` or `while` statement), but does _not_ allow shared pointers to unrelated types to be compared (e.g., via `<` or `>`). |=== == Deduction Guides [cols="1,4"] |=== | Name| Description | xref:bsl/shared_ptr-0b0.adoc[`shared_ptr<ELEMENT_TYPE>`] | Deduce the specified type `ELEMENT_TYPE` corresponding template parameter of the `bslma::ManagedPtr` supplied to the constructor of `shared_ptr`. | xref:bsl/shared_ptr-0b7.adoc[`shared_ptr<ELEMENT_TYPE>`] | Deduce the specified type `ELEMENT_TYPE` corresponding template parameter of the `bsl::weak_ptr` supplied to the constructor of `shared_ptr`. | xref:bsl/shared_ptr-0e.adoc[`shared_ptr<ELEMENT_TYPE>`] | Deduce the specified type `ELEMENT_TYPE` corresponding template parameter of the `std::unique_ptr` supplied to the constructor of `shared_ptr`. | xref:bsl/shared_ptr-0c.adoc[`shared_ptr<ELEMENT_TYPE>`] | Deduce the specified type `ELEMENT_TYPE` corresponding template parameter of the `bslma::ManagedPtr` supplied to the constructor of `shared_ptr`. This guide does not participate in deduction unless the specified `ALLOC` inherits from `bslma::Allocator`. | xref:bsl/shared_ptr-02.adoc[`shared_ptr<ELEMENT_TYPE>`] | Deduce the specified type `ELEMENT_TYPE` corresponding template parameter of the `std::unique_ptr` supplied to the constructor of `shared_ptr`. This guide does not participate in deduction unless the specified `ALLOC` inherits from `bslma::Allocator`. |=== == Friends [cols="1,4"] |=== | Name| Description | `bsl::shared_ptr` | This class provides a thread‐safe reference‐counted "smart pointer" to support "shared ownership" of objects: a shared pointer ensures that the shared object is destroyed, using the appropriate deletion method, only when there are no shared references to it. The object (of template parameter type `ELEMENT_TYPE`) referred to by a shared pointer may be accessed directly using the `‐>` operator, or the dereference operator (operator `*`) can be used to obtain a reference to that object. |=== == Non-Member Functions [cols="1,4"] |=== | Name| Description | xref:bsl/allocate_shared-01e.adoc[`allocate_shared`] | Return a `shared_ptr` object referring to and managing a new `ELEMENT_TYPE` object. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ELEMENT_TYPE` object, which is initialized by calling `allocator_traits<ALLOC>::construct` passing `basicAllocator`, an `ELEMENT_TYPE *` pointer to space for the new shared object, and the specified arguments `std::forward<ARGS>(args)...`. | xref:bsl/allocate_shared-01f.adoc[`allocate_shared`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a unbounded array. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` containing the specified `numElements` number of elements, and each element in the array is constructed from the specified `value`. | xref:bsl/allocate_shared-04.adoc[`allocate_shared`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a unbounded array. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` containing the specified `numElements` number of elements, and each element in the array is constructed from the specified `value`. If `basicAllocator` is 0, then the default allocator will be used instead. | xref:bsl/allocate_shared-05b.adoc[`allocate_shared`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a unbounded array. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` containing the specified `numElements` number of elements, and each element in the array is default constructed. If `basicAllocator` is 0, then the default allocator will be used instead. | xref:bsl/allocate_shared-05d.adoc[`allocate_shared`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a bounded array. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` object, and each element in the array is constructed from the specified `value`. | xref:bsl/allocate_shared-07.adoc[`allocate_shared`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a unbounded array. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` containing the specified `numElements` number of elements, and each element in the array is default constructed. | xref:bsl/allocate_shared-08.adoc[`allocate_shared`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a bounded array. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` object, and each element in the array is default constructed. If `basicAllocator` is 0, then the default allocator will be used instead. | xref:bsl/allocate_shared-0bb.adoc[`allocate_shared`] | Return a `shared_ptr` object referring to and managing a new `ELEMENT_TYPE` object. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ELEMENT_TYPE` object, which is initialized using the `ELEMENT_TYPE` constructor that takes the specified arguments `std::forward<ARGS>(args)...`. If `ELEMENT_TYPE` uses `bslma` allocators, then `basicAllocator` is passed as an extra argument in the final position. If `basicAllocator` is 0, then the default allocator will be used instead, and passed as the allocator, when appropriate, to the `ELEMENT_TYPE` constructor. | xref:bsl/allocate_shared-0c.adoc[`allocate_shared`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a bounded array. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` object, and each element in the array is constructed from the specified `value`. If `basicAllocator` is 0, then the default allocator will be used instead. | xref:bsl/allocate_shared-0f.adoc[`allocate_shared`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a bounded array. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` object, and each element in the array is default constructed. | xref:bsl/allocate_shared_for_overwrite-017.adoc[`allocate_shared_for_overwrite`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a bounded array. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` object, and the array is default‐constructed. If `basicAllocator` is 0, then the default allocator will be used instead. | xref:bsl/allocate_shared_for_overwrite-01c.adoc[`allocate_shared_for_overwrite`] | Return a `shared_ptr` object referring to and managing a new `ELEMENT_TYPE` object. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ELEMENT_TYPE` object, which is default‐constructed. If `basicAllocator` is 0, then the default allocator will be used instead. | xref:bsl/allocate_shared_for_overwrite-07.adoc[`allocate_shared_for_overwrite`] | Return a `shared_ptr` object referring to and managing a new `ELEMENT_TYPE` object. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ELEMENT_TYPE` object, which is default‐constructed. | xref:bsl/allocate_shared_for_overwrite-0d.adoc[`allocate_shared_for_overwrite`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a bounded array. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` object, and the array is default‐constructed. | xref:bsl/allocate_shared_for_overwrite-0ee2.adoc[`allocate_shared_for_overwrite`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a unbounded array. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` containing the specified `numElements` number of elements, and the array is default‐constructed. If `basicAllocator` is 0, then the default allocator will be used instead. | xref:bsl/allocate_shared_for_overwrite-0eed.adoc[`allocate_shared_for_overwrite`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a unbounded array. The specified `basicAllocator` will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` containing the specified `numElements` number of elements, and the array is default‐constructed. | xref:bsl/const_pointer_cast.adoc[`const_pointer_cast`] | Return a `shared_ptr<TO_TYPE>` object sharing ownership of the same object as the specified `source` shared pointer to the (template parameter) `FROM_TYPE`, and referring to `const_cast<TO_TYPE *>(source.get())`. Note that if `source` cannot be `const`‐cast to `TO_TYPE *`, then a compiler diagnostic will be emitted indicating the error. | xref:bsl/dynamic_pointer_cast.adoc[`dynamic_pointer_cast`] | Return a `shared_ptr<TO_TYPE>` object sharing ownership of the same object as the specified `source` shared pointer to the (template parameter) `FROM_TYPE`, and referring to `dynamic_cast<TO_TYPE*>(source.get())`. If `source` cannot be dynamically cast to `TO_TYPE *`, then an empty `shared_ptr<TO_TYPE>` object is returned. | xref:bsl/get_deleter.adoc[`get_deleter`] | Return the address of deleter used by the specified `p` shared pointer if the (template parameter) type `DELETER` is the type of the deleter installed in `p`, and a null pointer value otherwise. | xref:bsl/make_shared-02.adoc[`make_shared`] | Return a `shared_ptr` object referring to and managing a new `ELEMENT_TYPE` object. The default allocator will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ELEMENT_TYPE` object, which is initialized using the `ELEMENT_TYPE` constructor that takes the specified arguments `std::forward<ARGS>(args)...`. If `ELEMENT_TYPE` uses `bslma` allocators, then the default allocator is passed as an extra argument in the final position. | xref:bsl/make_shared-06.adoc[`make_shared`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a bounded array. The default allocator will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` object, and each element in the array is constructed from the specified `value`. | xref:bsl/make_shared-0a.adoc[`make_shared`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a bounded array. The default allocator will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` object, and each element in the array is default constructed. | xref:bsl/make_shared-0d.adoc[`make_shared`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a unbounded array. The default allocator will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` containing the specified `numElements` number of elements, and each element in the array is constructed from the specified `value`. | xref:bsl/make_shared-0e.adoc[`make_shared`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a unbounded array. The default allocator will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` containing the specified `numElements` number of elements, and each element in the array is default constructed. | xref:bsl/make_shared_for_overwrite-02.adoc[`make_shared_for_overwrite`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a unbounded array. The default allocator will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` containing the specified `numElements` number of elements, and the array is default‐constructed. | xref:bsl/make_shared_for_overwrite-054.adoc[`make_shared_for_overwrite`] | Return a `shared_ptr` object referring to and managing a new `ELEMENT_TYPE` object. The default allocator will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ELEMENT_TYPE` object, which is default‐constructed. | xref:bsl/make_shared_for_overwrite-05b.adoc[`make_shared_for_overwrite`] | Return a `shared_ptr` object referring to and managing a new `ARRAY_TYPE` object, where `ARRAY_TYPE` is a bounded array. The default allocator will be used to supply a single contiguous region of memory holding the returned shared pointer's internal representation and the new `ARRAY_TYPE` object, and the array is default‐constructed. | xref:bsl/operator_3way-0412.adoc[`operator<=>`] | Perform a three‐way comparison of the specified `ptr` and null pointer by using the comparison operators of `TYPE *`; return the result of that comparison. | xref:bsl/operator_3way-086.adoc[`operator<=>`] | Perform a three‐way comparison of the specified `lhs` and the specified `rhs` pointers by using the comparison operators of `LHS_TYPE *` and `RHS_TYPE *`; return the result of that comparison. | xref:bsl/operator_eq-0cd9.adoc[`operator==`] | Return `true` if the specified `lhs` shared pointer refers to the same object (if any) as that referred to by the specified `rhs` shared pointer (if any), and `false` otherwise; a compiler diagnostic will be emitted indicating the error unless a (raw) pointer to `LHS_TYPE` can be compared to a (raw) pointer to `RHS_TYPE`. Note that two shared pointers that compare equal do not necessarily manage the same object due to aliasing. | xref:bsl/operator_eq-0ec.adoc[`operator==`] | Return `true` if the specified `lhs` shared pointer does not refer to an object, and `false` otherwise. | xref:bsl/reinterpret_pointer_cast.adoc[`reinterpret_pointer_cast`] | Return a `shared_ptr<TO_TYPE>` object sharing ownership of the same object as the specified `source` shared pointer to the (template parameter) `FROM_TYPE`, and referring to `reinterpret_cast<TO_TYPE *>(source.get())`. Note that if `source` cannot be reinterpret_cast‐ed to `TO_TYPE *`, then a compiler diagnostic will be emitted indicating the error. | xref:bsl/static_pointer_cast.adoc[`static_pointer_cast`] | Return a `shared_ptr<TO_TYPE>` object sharing ownership of the same object as the specified `source` shared pointer to the (template parameter) `FROM_TYPE`, and referring to `static_cast<TO_TYPE *>(source.get())`. Note that if `source` cannot be statically cast to `TO_TYPE *`, then a compiler diagnostic will be emitted indicating the error. | xref:bsl/swap-092.adoc[`swap`] | Efficiently exchange the states of the specified `a` and `b` shared pointers such that each will refer to the object formerly referred to by the other, and each will manage the object formerly managed by the other. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#