[#bsl-shared_ptr-0a-operator_assign-05] = xref:bsl.adoc[bsl]::xref:bsl/shared_ptr-0a.adoc[shared_ptr]::operator= :relfileprefix: ../../ :mrdocs: Assignment operators == Synopses Declared in `<bslstl_sharedptr.h>` Make this shared pointer manage the same modifiable object as the specified `rhs` shared pointer to the (template parameter) type `COMPATIBLE_TYPE`, use the same deleter as `rhs`, and refer to `(ELEMENT_TYPE *)rhs.get()`; return a reference providing modifiable access to this shared pointer. Note that if `rhs` is empty, then this shared pointer will also be empty after the assignment. Also note that if `*this` is the same object as `rhs`, then this method has no effect. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/shared_ptr-0a.adoc[shared_ptr]& xref:bsl/shared_ptr-0a/operator_assign-0f.adoc[operator=](xref:bsl/shared_ptr-0a.adoc[shared_ptr] const& rhs) noexcept; ---- [.small]#xref:bsl/shared_ptr-0a/operator_assign-0f.adoc[_» more..._]# Make this shared pointer refer to and manage the same modifiable object as the specified `rhs` shared pointer to the (template parameter) type `COMPATIBLE_TYPE`, using the same deleter as `rhs` and referring to `(ELEMENT_TYPE *)rhs.get()`, and return a reference to this modifiable shared pointer. 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. Note that if `rhs` is empty, then this shared pointer will also be empty after the assignment. Assign from the specified compatible `shared_ptr` `rhs`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class COMPATIBLE_TYPE> xref:bsl/shared_ptr-0a.adoc[shared_ptr]& xref:bsl/shared_ptr-0a/operator_assign-097.adoc[operator=](xref:bsl/shared_ptr-0a.adoc[shared_ptr<COMPATIBLE_TYPE>] const& rhs) noexcept requires is_convertible<COMPATIBLE_TYPE *, ELEMENT_TYPE *>::value; ---- [.small]#xref:bsl/shared_ptr-0a/operator_assign-097.adoc[_» more..._]# Make this shared pointer refer to and manage the same modifiable object as the specified `rhs` shared pointer to the (template parameter) type `COMPATIBLE_TYPE`, using the same deleter as `rhs` and referring to `(ELEMENT_TYPE *)rhs.get()`, and return a reference to this modifiable shared pointer. 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. Reset `rhs` to an empty state, not pointing to any object, unless `*this` is the same object as `rhs`. This function does not exist unless a pointer to (template parameter) `COMPATIBLE_TYPE` is convertible to a pointer to the (template parameter) `ELEMENT_TYPE` of this `shared_ptr`. Note that if `rhs` is empty, then this shared pointer will also be empty after the assignment. Move‐assign from the specified compatible `shared_ptr` `rhs`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class COMPATIBLE_TYPE> xref:bsl/shared_ptr-0a.adoc[shared_ptr]& xref:bsl/shared_ptr-0a/operator_assign-09c.adoc[operator=](xref:bsl/shared_ptr-0a.adoc[shared_ptr<COMPATIBLE_TYPE>]&& rhs) noexcept requires is_convertible<COMPATIBLE_TYPE *, ELEMENT_TYPE *>::value; ---- [.small]#xref:bsl/shared_ptr-0a/operator_assign-09c.adoc[_» more..._]# Make this shared pointer manage the same modifiable object as the specified `rhs` shared pointer to the (template parameter) type `COMPATIBLE_TYPE`, use the same deleter as `rhs`, and refer to `rhs.get()`; return a reference providing modifiable access to this shared pointer. Reset `rhs` to an empty state, not pointing to any object, unless `*this` is the same object as `rhs`. Note that if `rhs` is empty, then this shared pointer will also be empty after the assignment. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/shared_ptr-0a.adoc[shared_ptr]& xref:bsl/shared_ptr-0a/operator_assign-0e.adoc[operator=](xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef<shared_ptr>] rhs) noexcept; ---- [.small]#xref:bsl/shared_ptr-0a/operator_assign-0e.adoc[_» more..._]# Transfer, to this shared pointer, ownership of the modifiable object managed by the specified `rhs` managed pointer to the (template parameter) type `COMPATIBLE_TYPE`, and make this shared pointer refer to `(ELEMENT_TYPE *)rhs.ptr()`. The deleter used in the `rhs` will be used to destroy the shared object when all references have been released. The _default_ _allocator_ is used to allocate a `SharedPtrRep`, if needed (users must use the copy‐constructor and swap instead of using this operator to supply an alternative allocator). 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. Note that if `rhs` is empty, then this shared pointer will be empty after the assignment. Also note that if `rhs` owns a reference to another shared object (due to a previous call to `shared_ptr<T>::managedPtr`) then this `shared_ptr` will adopt the `ManagedPtr`s ownership of that shared object. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class COMPATIBLE_TYPE> xref:bsl/shared_ptr-0a.adoc[shared_ptr]& xref:bsl/shared_ptr-0a/operator_assign-0a.adoc[operator=](xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[BloombergLP::bslma::ManagedPtr<COMPATIBLE_TYPE>] rhs) requires is_convertible<COMPATIBLE_TYPE *, ELEMENT_TYPE *>::value; ---- [.small]#xref:bsl/shared_ptr-0a/operator_assign-0a.adoc[_» more..._]# Transfer, to this shared pointer, ownership of the modifiable object managed by the specified `rhs` auto pointer to the (template parameter) type `COMPATIBLE_TYPE`, and make this shared pointer refer to `(ELEMENT_TYPE *)rhs.get()`. `delete(autoPtr.release())` will be called to destroy the shared object when all references have been released. 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. Note that if `rhs` is empty, then this shared pointer will be empty after the assignment. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class COMPATIBLE_TYPE> xref:bsl/shared_ptr-0a.adoc[shared_ptr]& xref:bsl/shared_ptr-0a/operator_assign-02.adoc[operator=](std::auto_ptr<COMPATIBLE_TYPE> rhs) requires is_convertible<COMPATIBLE_TYPE *, ELEMENT_TYPE *>::value; ---- [.small]#xref:bsl/shared_ptr-0a/operator_assign-02.adoc[_» more..._]# Transfer, to this shared pointer, ownership of the object managed by the specified `rhs` unique pointer to the (template parameter) type `COMPATIBLE_TYPE`, and make this shared pointer refer to `(ELEMENT_TYPE *)rhs.get()`. The deleter of `rhs` will be called to destroy the shared object when all references have been released. 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. This function does not exist unless `unique_ptr<COMPATIBLE_TYPE, DELETER>::pointer` is convertible to `ELEMENT_TYPE *`. Note that if `rhs` is empty, then this shared pointer will be empty after the assignment. Also note that this function creates a `shared_ptr` with an unspecified deleter type that satisfies this contract; the C++11 standard specifies the exact deleter that should be in use after assignment, so this implementation may be non‐conforming. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< class COMPATIBLE_TYPE, class UNIQUE_DELETER> xref:bsl/shared_ptr-0a.adoc[shared_ptr]& xref:bsl/shared_ptr-0a/operator_assign-090.adoc[operator=](std::unique_ptr<COMPATIBLE_TYPE, UNIQUE_DELETER>&& rhs) requires is_convertible< typename std::unique_ptr<COMPATIBLE_TYPE, UNIQUE_DELETER>::pointer, ELEMENT_TYPE *>::value; ---- [.small]#xref:bsl/shared_ptr-0a/operator_assign-090.adoc[_» more..._]# [.small]#Created with https://www.mrdocs.com[MrDocs]#