unique_ptr Class
所有されているオブジェクトへのポインターを格納します。オブジェクトは、他の unique_ptrによって所有されていません。オブジェクトは unique_ptr が破棄されるときに破棄されます。
template<class Type, class Del = default_delete<Type> >
class unique_ptr {
public:
typedef Type element_type;
typedef Del deleter_type;
typedef T1 pointer;
unique_ptr ();
unique_ptr (
nullptr_t _Nptr
);
explicit unique_ptr (
pointer _Ptr
);
unique_ptr (
pointer _Ptr,
typename conditional<
is_reference<Del>::value,
Del,
typename add_reference<const Del>::type
>::type _Deleter
);
unique_ptr (
pointer _Ptr,
typename remove_reference<Del>::type&& _Deleter
);
unique_ptr (
unique_ptr&& _Right
);
template<class Type2, Class Del2>
unique_ptr (
unique_ptr<Type2, Del2>&& _Right
);
~unique_ptr ();
unique_ptr& operator= (
unique_ptr&& _Right
);
template<class Type2, Class Del2>
unique_ptr& operator= (
unique_ptr<Type2, Del2>&& _Right
);
void swap (
unique_ptr& _Right
);
pointer release ();
void reset (
pointer _Ptr = pointer()
);
pointer get () const;
Type& operator* () const;
pointer operator-> () const;
Del& get_deleter ();
const Del& get_deleter () const;
explicit operator bool () const;
unique_ptr(
const unique_ptr& _Right
) = delete;
unique_ptr& operator=(
const unique_ptr& _Right
) = delete;
private:
pointer stored_ptr; // exposition only
Del stored_deleter; // exposition only
};
パラメーター
_Right
unique_ptr_Nptr
std::nullptr_t 型の rvalue。_Ptr
pointer_Deleter
unique_ptrにバインドされる deleter 関数。
例外
例外は unique_ptrによって生成されません。
解説
unique_ptr のクラスは auto_ptrによりも、STL コンテナー要素として使用できます。
unique_ptr は、一意のリソースを管理します。unique_ptr の各オブジェクトは null ポインターを所有または格納するオブジェクトへのポインターを格納します。リソースは unique_ptr 複数のオブジェクトが所有することはできません; 特定のリソースを所有する unique_ptr のオブジェクトが破棄されるときに、リソースが解放されます。unique_ptr のオブジェクトは移動、コピーする可能性があります。; 詳細については、右辺値参照宣言子: &&"を参照してください。
リソースがわかっている型 Del の deleter に格納されたオブジェクトを呼び出してリソースが特定の unique_ptrのような割り当てを解放されます。_Ptr が指し示すリソースが割り当てられていると new、delete _Ptrの呼び出しによって解放できると既定 deleterdefault_delete<Type> であると仮定します。(部分的特殊化 unique_ptr<Type[]> は new[] で割り当てられた配列オブジェクトを管理し、デフォルトの deleterdefault_delete<Type[]> を持ち、delete[] _Ptr の呼び出しを特殊化します。)
リソース、stored_ptr に格納されているポインター型に pointerがあります。これは Del::pointer を定義する場合、および Type *そうでない場合です。deleter は状態非依存の場合 deleter に格納されたオブジェクト stored_deleter は、オブジェクトのスペースを消費しません。Del が参照型である場合があることに注意してください。
メンバー
コンストラクター
unique_ptrの 7 種類のコンストラクターがあります。 |
Typedef
テンプレート パラメーターのシノニム Del。 |
|
Typeテンプレート パラメーターのシノニム. |
|
Del::pointer を定義する場合、Type * のシノニム。 |
メンバー関数
stored_ptr を返します。 |
|
stored_deleter への参照を返します。 |
|
pointer() を stored_ptr に格納し、前のコンテンツを返します。 |
|
現在リソースを解放し、新しいリソースを受け取ります。 |
|
指定された unique_ptrの交換とリソース deleter。 |
演算子
operator bool |
この演算子は、bool に変換可能な型の値を返します。bool への変換結果は、get() != pointer() の場合は true、それ以外の場合は false です。 |
operator-> |
このメンバー関数は、を返します stored_ptr. |
operator* |
メンバー関数の returns*stored_ptr. |
現在の unique_ptrに unique_ptr (または) pointer-typeの値を再配置。 |
必要条件
ヘッダー: <memory>
名前空間: std