Namespaces
Variants

std::auto_ptr<T>:: operator auto_ptr<Y>

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)
template < class Y >
operator auto_ptr_ref < Y > ( ) throw ( ) ;
(1) (C++11で非推奨)
(C++17で削除)
template < class Y >
operator auto_ptr < Y > ( ) throw ( ) ;
(2) (C++11で非推奨)
(C++17で削除)

* this を異なる型 Y auto_ptr に変換します。

1) 実装定義の型を返し、これは * this への参照を保持します。 std::auto_ptr はこのテンプレートから 変換可能 かつ 代入可能 です。実装はこのテンプレートに異なる名前を付けるか、同等の機能を他の方法で実装することが許可されています。
2) auto_ptr を新しく構築し、そのポインタは release() を呼び出すことで取得されます。

パラメータ

(なし)

戻り値

1) 参照を保持する実装定義型 * this
2) release() を呼び出して取得したポインタを持つ auto_ptr

注記

auto_ptr_ref からのコンストラクタとコピー代入演算子は、 std::auto_ptr を無名一時オブジェクトからコピー構築および代入することを可能にするために提供されています。そのコピーコンストラクタとコピー代入演算子は引数を非const参照として受け取るため、右辺値引数に直接バインドすることはできません。しかし、ユーザー定義変換 (1) または (2) が実行され(これにより元の auto_ptr が解放されます)、その後値で auto_ptr_ref を受け取るコンストラクタまたはコピー代入演算子が呼び出されます。これは ムーブセマンティクス の初期の実装です。