[#bsl-shared_ptr-0a]
= xref:bsl.adoc[bsl]::shared&lowbar;ptr
:relfileprefix: ../
:mrdocs:

Thread&hyphen;safe reference&hyphen;counted smart pointer with shared ownership&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 shared&lowbar;ptr;
----

== Description

This class provides a thread&hyphen;safe reference&hyphen;counted &quot;smart pointer&quot; to support &quot;shared ownership&quot; of objects&colon; a shared pointer ensures that the shared object is destroyed, using the appropriate deletion method, only when there are no shared references to it&period; The object (of template parameter type `ELEMENT&lowbar;TYPE`) referred to by a shared pointer may be accessed directly using the `&hyphen;&gt;` operator, or the dereference operator (operator `&ast;`) can be used to obtain a reference to that object&period;

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&lowbar;TYPE`), but this need not always be true in the presence of conversions or &quot;aliasing&quot;&colon; the object referred to (of template parameter type `ELEMENT&lowbar;TYPE`) by the shared pointer may differ from the object of type `COMPATIBLE&lowbar;TYPE` (see the &quot;Aliasing&quot; section in the component&hyphen;level documentation) referred to by the shared pointer representation&period;

More generally, this class supports a complete set of _in_&hyphen;_core_ pointer semantic operations&period;

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:bsl/shared_ptr-0a/element_type.adoc[`element&lowbar;type`] 
| Alias to the element type managed by this `shared&lowbar;ptr`&period;
| xref:bsl/shared_ptr-0a/weak_type.adoc[`weak&lowbar;type`] 
| `weak&lowbar;type` is an alias to a weak pointer with the same element type as this `shared&lowbar;ptr`&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/shared_ptr-0a/2constructor-03f.adoc[`shared&lowbar;ptr`]         [.small]#[constructor]#
| Constructors
| xref:bsl/shared_ptr-0a/2destructor.adoc[`&#126;shared&lowbar;ptr`] [.small]#[destructor]#
| Destroy this `shared&lowbar;ptr` and release its managed object if last owner&period;
| xref:bsl/shared_ptr-0a/operator_assign-05.adoc[`operator&equals;`] 
| Assignment operators
| xref:bsl/shared_ptr-0a/clear.adoc[`clear`] 
| Reset this `shared&lowbar;ptr` to the empty state&period;
| 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&period;
| xref:bsl/shared_ptr-0a/load-06.adoc[`load`] 
| `load` overloads
| xref:bsl/shared_ptr-0a/loadAlias.adoc[`loadAlias`] 
| Reset this `shared&lowbar;ptr` as an alias sharing ownership with `source`&period;
| xref:bsl/shared_ptr-0a/managedPtr.adoc[`managedPtr`] 
| Return a `ManagedPtr` referring to the same object as this `shared&lowbar;ptr`&period;
| xref:bsl/shared_ptr-0a/numReferences.adoc[`numReferences`] 
| Return a &quot;snapshot&quot; of the number of shared pointers (including this one) that share ownership of the object managed by this shared pointer&period;
| xref:bsl/shared_ptr-0a/operator_star.adoc[`operator&ast;`] 
| Return a reference providing modifiable access to the object referred to by this shared pointer&period;
| xref:bsl/shared_ptr-0a/operator_ptr.adoc[`operator&hyphen;&gt;`] 
| 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&period;
| xref:bsl/shared_ptr-0a/operator_subs.adoc[`operator&lsqb;&rsqb;`] 
| Return a reference to the element at the specified `index`&period;
| xref:bsl/shared_ptr-0a/owner_before-0f.adoc[`owner&lowbar;before`] 
| Return whether this `shared&lowbar;ptr` precedes `other` in owner order&period;
| xref:bsl/shared_ptr-0a/owner_equal-08.adoc[`owner&lowbar;equal`] 
| Return whether this pointer shares ownership with `other`&period;
| xref:bsl/shared_ptr-0a/owner_hash.adoc[`owner&lowbar;hash`] 
| Return a hash value based on this pointer&apos;s ownership identity&period;
| 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&period;
| xref:bsl/shared_ptr-0a/release.adoc[`release`] 
| Release ownership and return the pointer and representation addresses&period;
| xref:bsl/shared_ptr-0a/rep.adoc[`rep`] 
| Return the address providing modifiable access to the `BloombergLP&colon;&colon;bslma&colon;&colon;SharedPtrRep` object used by this shared pointer, or 0 if this shared pointer is empty&period;
| xref:bsl/shared_ptr-0a/reset-0c8.adoc[`reset`] 
| `reset` overloads
| xref:bsl/shared_ptr-0a/swap.adoc[`swap`] 
| Exchange the state of this `shared&lowbar;ptr` with `other`&period;
| xref:bsl/shared_ptr-0a/unique.adoc[`unique`] 
| Return whether this `shared&lowbar;ptr` is the unique owner of its object&period;
| xref:bsl/shared_ptr-0a/use_count.adoc[`use&lowbar;count`] 
| Return a &quot;snapshot&quot; of the number of shared pointers (including this one) that share ownership of the object managed by this shared pointer&period;
| xref:bsl/shared_ptr-0a/2conversion-01.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;shared&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;
| xref:bsl/shared_ptr-0a/2conversion-05.adoc[`operator BoolType`] 
| Return whether this `shared&lowbar;ptr` refers to an object&period;
|===


== Deduction Guides

[cols="1,4"]
|===
| Name| Description
| xref:bsl/shared_ptr-0b0.adoc[`shared&lowbar;ptr&lt;ELEMENT&lowbar;TYPE&gt;`] 
| Deduce the specified type `ELEMENT&lowbar;TYPE` corresponding template parameter of the `bslma&colon;&colon;ManagedPtr` supplied to the constructor of `shared&lowbar;ptr`&period;
| xref:bsl/shared_ptr-0b7.adoc[`shared&lowbar;ptr&lt;ELEMENT&lowbar;TYPE&gt;`] 
| Deduce the specified type `ELEMENT&lowbar;TYPE` corresponding template parameter of the `bsl&colon;&colon;weak&lowbar;ptr` supplied to the constructor of `shared&lowbar;ptr`&period;
| xref:bsl/shared_ptr-0e.adoc[`shared&lowbar;ptr&lt;ELEMENT&lowbar;TYPE&gt;`] 
| Deduce the specified type `ELEMENT&lowbar;TYPE` corresponding template parameter of the `std&colon;&colon;unique&lowbar;ptr` supplied to the constructor of `shared&lowbar;ptr`&period;
| xref:bsl/shared_ptr-0c.adoc[`shared&lowbar;ptr&lt;ELEMENT&lowbar;TYPE&gt;`] 
| Deduction guide for constructing `shared&lowbar;ptr` from `ManagedPtr`&period;
| xref:bsl/shared_ptr-02.adoc[`shared&lowbar;ptr&lt;ELEMENT&lowbar;TYPE&gt;`] 
| Deduction guide for constructing `shared&lowbar;ptr` from `std&colon;&colon;unique&lowbar;ptr`&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `bsl::shared&lowbar;ptr`
| Thread&hyphen;safe reference&hyphen;counted smart pointer with shared ownership&period;
|===

== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/allocate_shared-01e.adoc[`allocate&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared-01f.adoc[`allocate&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared-04.adoc[`allocate&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared-05b.adoc[`allocate&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared-05d.adoc[`allocate&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared-07.adoc[`allocate&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared-08.adoc[`allocate&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared-0bb.adoc[`allocate&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared-0c.adoc[`allocate&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared-0f.adoc[`allocate&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared_for_overwrite-017.adoc[`allocate&lowbar;shared&lowbar;for&lowbar;overwrite`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared_for_overwrite-01c.adoc[`allocate&lowbar;shared&lowbar;for&lowbar;overwrite`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared_for_overwrite-07.adoc[`allocate&lowbar;shared&lowbar;for&lowbar;overwrite`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared_for_overwrite-0d.adoc[`allocate&lowbar;shared&lowbar;for&lowbar;overwrite`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared_for_overwrite-0ee2.adoc[`allocate&lowbar;shared&lowbar;for&lowbar;overwrite`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/allocate_shared_for_overwrite-0eed.adoc[`allocate&lowbar;shared&lowbar;for&lowbar;overwrite`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/const_pointer_cast.adoc[`const&lowbar;pointer&lowbar;cast`]
| Return a `shared&lowbar;ptr` obtained by `const&lowbar;cast` from `source`&period;
| xref:bsl/dynamic_pointer_cast.adoc[`dynamic&lowbar;pointer&lowbar;cast`]
| Return a `shared&lowbar;ptr` obtained by `dynamic&lowbar;cast` from `source`&period;
| xref:bsl/get_deleter.adoc[`get&lowbar;deleter`]
| Return a pointer to the deleter of type `DELETER` used by `p`, or null&period;
| xref:bsl/make_shared-02.adoc[`make&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/make_shared-06.adoc[`make&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/make_shared-0a.adoc[`make&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/make_shared-0d.adoc[`make&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/make_shared-0e.adoc[`make&lowbar;shared`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/make_shared_for_overwrite-02.adoc[`make&lowbar;shared&lowbar;for&lowbar;overwrite`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/make_shared_for_overwrite-054.adoc[`make&lowbar;shared&lowbar;for&lowbar;overwrite`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/make_shared_for_overwrite-05b.adoc[`make&lowbar;shared&lowbar;for&lowbar;overwrite`]
| Return a `shared&lowbar;ptr` managing a newly created object&period;
| xref:bsl/operator_3way-0412.adoc[`operator&lt;&equals;&gt;`]
| Perform a three&hyphen;way comparison of the specified `ptr` and null pointer by using the comparison operators of `TYPE &ast;`&semi; return the result of that comparison&period;
| xref:bsl/operator_3way-086.adoc[`operator&lt;&equals;&gt;`]
| Compare `lhs` and `rhs` three&hyphen;way by their stored pointers&period;
| xref:bsl/operator_eq-0cd9.adoc[`operator&equals;&equals;`]
| Return whether `lhs` and `rhs` refer to the same object&period;
| xref:bsl/operator_eq-0ec.adoc[`operator&equals;&equals;`]
| Return `true` if the specified `lhs` shared pointer does not refer to an object, and `false` otherwise&period;
| xref:bsl/reinterpret_pointer_cast.adoc[`reinterpret&lowbar;pointer&lowbar;cast`]
| Return a `shared&lowbar;ptr` obtained by `reinterpret&lowbar;cast` from `source`&period;
| xref:bsl/static_pointer_cast.adoc[`static&lowbar;pointer&lowbar;cast`]
| Return a `shared&lowbar;ptr` obtained by `static&lowbar;cast` from `source`&period;
| xref:bsl/swap-092.adoc[`swap`]
| Exchange the states of the specified `shared&lowbar;ptr` objects `a` and `b`&period;
|===


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