Namespaces
Variants
Views
Actions

std::shared_ptr::operator=

From cppreference.com
< cpp‎ | memory‎ | shared ptr
Revision as of 15:54, 2 November 2012 by P12bot (Talk | contribs)

 
 
 
 
 

Template:ddcl list begin <tr class="t-dcl ">

<td >
shared_ptr& operator=( const shared_ptr& r );
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class Y >
shared_ptr& operator=( const shared_ptr<Y>& r );
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
shared_ptr& operator=( shared_ptr&& r );
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class Y >
shared_ptr& operator=( shared_ptr<Y>&& r );
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class Y >
shared_ptr& operator=( std::auto_ptr<Y>&& r );
</td>

<td > (3) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class Y, class Deleter >
shared_ptr& operator=( std::unique_ptr<Y,Deleter>&& r );
</td>

<td > (4) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

Replaces the managed object with the one managed by r.

1) Shares ownership of the object managed by r. If r manages no object, *this manages no object too. The templated overload doesn't participate in the overload resolution if Y* is not implicitly convertible to T*. Equivalent to shared_ptr<T> p(r).swap(*this).

2) Move-assigns a shared_ptr from r. After the assignment, *this contains a copy of the previous state of r, r is empty. The templated overload doesn't participate in the overload resolution if Y* is not implicitly convertible to T*. Equivalent to shared_ptr<T> p(std::move(r)).swap(*this).

3)

4) Transfers the ownership of the object managed by r to *this. The deleter associated to r is stored for future deletion of the managed object. r manages no object after the call. Equivalent to shared_ptr<T> p(std::move(r)).swap(*this).

Contents

Parameters

r - another smart pointer to share the ownership to or acquire the ownership from

Return value

*this

Notes

The implementation may meet the requirements without creating a temporary shared_ptr object.

Exceptions

1-2)
noexcept specification:  
noexcept
  

3) (none)

4-5)
noexcept specification:  
noexcept
  

Example

See also

Template:cpp/memory/shared ptr/dcl list reset