Namespaces
Variants

std::shared_ptr<T>:: operator=

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (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) (until C++23)
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) 実装定義の例外をスローする可能性があります。

関連項目

管理対象オブジェクトを置き換える
(公開メンバ関数)