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

Assignment operators

== Synopses

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

Make this shared pointer manage the same modifiable object as the specified `rhs` shared pointer to the (template parameter) type `COMPATIBLE&lowbar;TYPE`, use the same deleter as `rhs`, and refer to `(ELEMENT&lowbar;TYPE &ast;)rhs&period;get()`&semi; return a reference providing modifiable access to this shared pointer&period; Note that if `rhs` is empty, then this shared pointer will also be empty after the assignment&period; Also note that if `&ast;this` is the same object as `rhs`, then this method has no effect&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr]&
xref:bsl/shared_ptr-0a/operator_assign-0f.adoc[operator&equals;](xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr] const& rhs) noexcept;
----

[.small]#xref:bsl/shared_ptr-0a/operator_assign-0f.adoc[_» more&period;&period;&period;_]#

Make this shared pointer refer to and manage the same modifiable object as the specified `rhs` shared pointer to the (template parameter) type `COMPATIBLE&lowbar;TYPE`, using the same deleter as `rhs` and referring to `(ELEMENT&lowbar;TYPE &ast;)rhs&period;get()`, and return a reference to this modifiable shared pointer&period; If this shared pointer is already managing a (possibly shared) object, then release the shared reference to that object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object&period; Note that if `rhs` is empty, then this shared pointer will also be empty after the assignment&period; Assign from the specified compatible `shared&lowbar;ptr` `rhs`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class COMPATIBLE&lowbar;TYPE&gt;
xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr]&
xref:bsl/shared_ptr-0a/operator_assign-097.adoc[operator&equals;](xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr&lt;COMPATIBLE&lowbar;TYPE&gt;] const& rhs) noexcept
requires is&lowbar;convertible&lt;COMPATIBLE&lowbar;TYPE &ast;, ELEMENT&lowbar;TYPE &ast;&gt;&colon;&colon;value;
----

[.small]#xref:bsl/shared_ptr-0a/operator_assign-097.adoc[_» more&period;&period;&period;_]#

Make this shared pointer refer to and manage the same modifiable object as the specified `rhs` shared pointer to the (template parameter) type `COMPATIBLE&lowbar;TYPE`, using the same deleter as `rhs` and referring to `(ELEMENT&lowbar;TYPE &ast;)rhs&period;get()`, and return a reference to this modifiable shared pointer&period; If this shared pointer is already managing a (possibly shared) object, then release the shared reference to that object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object&period; Reset `rhs` to an empty state, not pointing to any object, unless `&ast;this` is the same object as `rhs`&period; This function does not exist unless a pointer to (template parameter) `COMPATIBLE&lowbar;TYPE` is convertible to a pointer to the (template parameter) `ELEMENT&lowbar;TYPE` of this `shared&lowbar;ptr`&period; Note that if `rhs` is empty, then this shared pointer will also be empty after the assignment&period; Move&hyphen;assign from the specified compatible `shared&lowbar;ptr` `rhs`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class COMPATIBLE&lowbar;TYPE&gt;
xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr]&
xref:bsl/shared_ptr-0a/operator_assign-09c.adoc[operator&equals;](xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr&lt;COMPATIBLE&lowbar;TYPE&gt;]&& rhs) noexcept
requires is&lowbar;convertible&lt;COMPATIBLE&lowbar;TYPE &ast;, ELEMENT&lowbar;TYPE &ast;&gt;&colon;&colon;value;
----

[.small]#xref:bsl/shared_ptr-0a/operator_assign-09c.adoc[_» more&period;&period;&period;_]#

Make this shared pointer manage the same modifiable object as the specified `rhs` shared pointer to the (template parameter) type `COMPATIBLE&lowbar;TYPE`, use the same deleter as `rhs`, and refer to `rhs&period;get()`&semi; return a reference providing modifiable access to this shared pointer&period; Reset `rhs` to an empty state, not pointing to any object, unless `&ast;this` is the same object as `rhs`&period; Note that if `rhs` is empty, then this shared pointer will also be empty after the assignment&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr]&
xref:bsl/shared_ptr-0a/operator_assign-0e.adoc[operator&equals;](xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef&lt;shared&lowbar;ptr&gt;] rhs) noexcept;
----

[.small]#xref:bsl/shared_ptr-0a/operator_assign-0e.adoc[_» more&period;&period;&period;_]#

Transfer, to this shared pointer, ownership of the modifiable object managed by the specified `rhs` managed pointer to the (template parameter) type `COMPATIBLE&lowbar;TYPE`, and make this shared pointer refer to `(ELEMENT&lowbar;TYPE &ast;)rhs&period;ptr()`&period; The deleter used in the `rhs` will be used to destroy the shared object when all references have been released&period; The _default_ _allocator_ is used to allocate a `SharedPtrRep`, if needed (users must use the copy&hyphen;constructor and swap instead of using this operator to supply an alternative allocator)&period; If this shared pointer is already managing a (possibly shared) object, then release the reference to that shared object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object&period; Note that if `rhs` is empty, then this shared pointer will be empty after the assignment&period; Also note that if `rhs` owns a reference to another shared object (due to a previous call to `shared&lowbar;ptr&lt;T&gt;&colon;&colon;managedPtr`) then this `shared&lowbar;ptr` will adopt the `ManagedPtr`s ownership of that shared object&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class COMPATIBLE&lowbar;TYPE&gt;
xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr]&
xref:bsl/shared_ptr-0a/operator_assign-0a.adoc[operator&equals;](xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[BloombergLP::bslma::ManagedPtr&lt;COMPATIBLE&lowbar;TYPE&gt;] rhs)
requires is&lowbar;convertible&lt;COMPATIBLE&lowbar;TYPE &ast;, ELEMENT&lowbar;TYPE &ast;&gt;&colon;&colon;value;
----

[.small]#xref:bsl/shared_ptr-0a/operator_assign-0a.adoc[_» more&period;&period;&period;_]#

Transfer, to this shared pointer, ownership of the modifiable object managed by the specified `rhs` auto pointer to the (template parameter) type `COMPATIBLE&lowbar;TYPE`, and make this shared pointer refer to `(ELEMENT&lowbar;TYPE &ast;)rhs&period;get()`&period; `delete(autoPtr&period;release())` will be called to destroy the shared object when all references have been released&period; If this shared pointer is already managing a (possibly shared) object, then release the reference to that shared object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object&period; Note that if `rhs` is empty, then this shared pointer will be empty after the assignment&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class COMPATIBLE&lowbar;TYPE&gt;
xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr]&
xref:bsl/shared_ptr-0a/operator_assign-02.adoc[operator&equals;](std::auto&lowbar;ptr&lt;COMPATIBLE&lowbar;TYPE&gt; rhs)
requires is&lowbar;convertible&lt;COMPATIBLE&lowbar;TYPE &ast;, ELEMENT&lowbar;TYPE &ast;&gt;&colon;&colon;value;
----

[.small]#xref:bsl/shared_ptr-0a/operator_assign-02.adoc[_» more&period;&period;&period;_]#

Transfer, to this shared pointer, ownership of the object managed by the specified `rhs` unique pointer to the (template parameter) type `COMPATIBLE&lowbar;TYPE`, and make this shared pointer refer to `(ELEMENT&lowbar;TYPE &ast;)rhs&period;get()`&period; The deleter of `rhs` will be called to destroy the shared object when all references have been released&period; If this shared pointer is already managing a (possibly shared) object, then release the reference to that shared object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object&period; This function does not exist unless `unique&lowbar;ptr&lt;COMPATIBLE&lowbar;TYPE, DELETER&gt;&colon;&colon;pointer` is convertible to `ELEMENT&lowbar;TYPE &ast;`&period; Note that if `rhs` is empty, then this shared pointer will be empty after the assignment&period; Also note that this function creates a `shared&lowbar;ptr` with an unspecified deleter type that satisfies this contract&semi; the C&plus;&plus;11 standard specifies the exact deleter that should be in use after assignment, so this implementation may be non&hyphen;conforming&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class COMPATIBLE&lowbar;TYPE,
    class UNIQUE&lowbar;DELETER&gt;
xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr]&
xref:bsl/shared_ptr-0a/operator_assign-090.adoc[operator&equals;](std::unique&lowbar;ptr&lt;COMPATIBLE&lowbar;TYPE, UNIQUE&lowbar;DELETER&gt;&& rhs)
requires is&lowbar;convertible&lt;
            typename std&colon;&colon;unique&lowbar;ptr&lt;COMPATIBLE&lowbar;TYPE, UNIQUE&lowbar;DELETER&gt;&colon;&colon;pointer,
                                     ELEMENT&lowbar;TYPE &ast;&gt;&colon;&colon;value;
----

[.small]#xref:bsl/shared_ptr-0a/operator_assign-090.adoc[_» more&period;&period;&period;_]#


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