std::shared_ptr<T>::operator=
From cppreference.com
< cpp | memory | shared ptr
| shared_ptr& operator=( const shared_ptr& r ) noexcept; |
(1) | |
| template< class Y > shared_ptr& operator=( const shared_ptr<Y>& r ) noexcept; |
(2) | |
| shared_ptr& operator=( shared_ptr&& r ) noexcept; |
(3) | |
| template< class Y > shared_ptr& operator=( shared_ptr<Y>&& r ) noexcept; |
(4) | |
| template< class Y > shared_ptr& operator=( std::auto_ptr<Y>&& r ); |
(5) | (C++11で非推奨) (C++17で削除) |
| template< class Y, class Deleter > shared_ptr& operator=( std::unique_ptr<Y, Deleter>&& r ); |
(6) | |
r が管理するオブジェクトで、管理対象を置き換えます。
もし *this が既にオブジェクトを所有しており、それがそのオブジェクトを所有する最後の shared_ptr で、かつ r が *this と同じでない場合、そのオブジェクトは所有デリータを通じて破棄されます。
1,2) r が管理するオブジェクトの所有権を共有します。もし r がオブジェクトを管理していない場合、*this もオブジェクトを管理しません。 shared_ptr<T>(r).swap(*this) と同等です。
3,4) r から
shared_ptr をムーブ代入します。代入後、*this は r の以前の状態のコピーを含み、r は空になります。 shared_ptr<T>(std::move(r)).swap(*this) と同等です。5) r が管理するオブジェクトの所有権を *this に移動します。もし r がオブジェクトを管理していない場合、*this もオブジェクトを管理しません。代入後、*this は r が以前保持していたポインタを含み、use_count() == 1 となります。また、r は空になります。 shared_ptr<T>(r).swap(*this) と同等です。
6) r が管理するオブジェクトの所有権を *this に移動します。 r に関連付けられたデリータは、管理対象オブジェクトの将来の削除のために保存されます。 r は呼び出し後にオブジェクトを管理しません。 shared_ptr<T>(std::move(r)).swap(*this) と同等です。
目次 |
[編集] パラメータ
| r | - | 所有権を共有するか、または所有権を取得する別のスマートポインタ |
[編集] 戻り値
*this
[編集] ノート
実装は、一時的な shared_ptr オブジェクトを作成せずに要件を満たす場合があります。
[編集] 例外
5,6) 実装定義の例外を送出する可能性があります。
[編集] 例
| このセクションは未完成です 理由: 例がありません |
[編集] 関連項目
| 管理対象オブジェクトを置き換える (public member function) |