std::weak_ptr::operator=

From cppreference.com
< cpp‎ | memory‎ | weak ptr
 
 
Utilities library
Type support (basic types, RTTI, type traits)
Dynamic memory management
Error handling
Program utilities
Variadic functions
Date and time
Function objects
(C++11)
Relational operators
Optional and any
(C++17)
(C++17)
Pairs and tuples
(C++11)
(C++17)
Swap, forward and move
(C++14)
(C++11)
(C++11)
Type operations
(C++11)
(C++17)
 
 
 
weak_ptr& operator=( const weak_ptr& r );
(1) (since C++11)
template< class Y >
weak_ptr& operator=( const weak_ptr<Y>& r );
(2) (since C++11)
template< class Y >
weak_ptr& operator=( const shared_ptr<Y>& r );
(3) (since C++11)
weak_ptr& operator=( weak_ptr&& r );
(4) (since C++14)
template< class Y >
weak_ptr& operator=( weak_ptr<Y>&& r );
(5) (since C++14)

Replaces the managed object with the one managed by r. The object is shared with r. If r manages no object, *this manages no object too.

1-3) Equivalent to std::weak_ptr<T>(r).swap(*this).
4,5) Equivalent to std::weak_ptr<T>(std::move(r)).swap(*this).

Contents

[edit] Parameters

r - smart pointer to share an object with

[edit] Return value

*this

[edit] Exceptions

noexcept specification:  
noexcept
  

[edit] Notes

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

[edit] See also

creates a new weak_ptr
(public member function)
swaps the managed objects
(public member function)