std::weak_ptr<T>::operator=
From cppreference.com
| weak_ptr& operator=( const weak_ptr& r ) noexcept; |
(1) | (C++11以降) |
| template< class Y > weak_ptr& operator=( const weak_ptr<Y>& r ); noexcept; |
(2) | (C++11以降) |
| template< class Y > weak_ptr& operator=( const shared_ptr<Y>& r ); noexcept; |
(3) | (C++11以降) |
| weak_ptr& operator=( weak_ptr&& r ) noexcept; |
(4) | (C++11以降) |
| template< class Y > weak_ptr& operator=( weak_ptr<Y>&& r ); noexcept; |
(5) | (C++11以降) |
管理しているオブジェクトを、r が管理しているオブジェクトで置き換えます。オブジェクトは r と共有されます。r がオブジェクトを管理していない場合、*this もオブジェクトを管理しません。
1-3) std::weak_ptr<T>(r).swap(*this) と同等です。
4,5) std::weak_ptr<T>(std::move(r)).swap(*this) と同等です。
目次 |
[編集] パラメータ
| r | - | オブジェクトを共有するスマートポインタ |
[編集] 戻り値
*this
[編集] メモ
実装では、一時的な weak_ptr オブジェクトを作成せずに要件を満たすことができます。
[編集] 欠陥レポート
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 2315 | C++11 | weak_ptr のムーブセマンティクスが有効になっていなかった | 有効化されました。 |
[編集] 関連項目
新しい weak_ptr を作成する((public member function) [[編集]]) | |
| 管理対象オブジェクトを交換する ((public member function) [[編集]]) |