std::weak_ptr<T>::operator=
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Memory management library
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
Garbage collector support (until C++23)
(exposition only*)
(C++11)
(C++23)
(C++11)
(C++17)
(C++11)
(C++11)
(C++20)
(C++20)
(C++17)
(C++11)
(C++17)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(until C++20*)
(until C++20*)
(until C++20*)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)
(C++11)
(C++17)
(C++20)
(C++17)
(C++11)
(C++11)
(C++11)
(until C++17*)
(C++11)
(C++17)
(C++26)
(C++26)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++11)
(C++20)
(C++11)
(C++11)
(C++20)
(C++26)
std::weak_ptr
Member functions
weak_ptr::operator=
Modifiers
Observers
(C++26)
(C++26)
Non-member functions
Helper classes
(C++20)
Deduction guides (C++17)
weak_ptr& operator=( const weak_ptr& r ) noexcept;
(1)
(since C++11)
template< class Y >
weak_ptr& operator=( const weak_ptr<Y>& r ) noexcept;
(2)
(since C++11)
weak_ptr& operator=( const weak_ptr<Y>& r ) noexcept;
template< class Y >
weak_ptr& operator=( const shared_ptr<Y>& r ) noexcept;
(3)
(since C++11)
weak_ptr& operator=( const shared_ptr<Y>& r ) noexcept;
weak_ptr& operator=( weak_ptr&& r ) noexcept;
(4)
(since C++11)
template< class Y >
weak_ptr& operator=( weak_ptr<Y>&& r ) noexcept;
(5)
(since C++11)
weak_ptr& operator=( weak_ptr<Y>&& r ) noexcept;
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).
[edit] Parameters
r
-
smart pointer to share an object with
[edit] Return value
*this
[edit] Notes
The implementation may meet the requirements without creating a temporary weak_ptr
object.
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 2315 | C++11 | move semantic was not enabled for weak_ptr
|
enabled |