名前空間
変種
操作

std::experimental::static_pointer_cast、std::experimental::dynamic_pointer_cast、std::experimental::const_pointer_cast、std::experimental::reinterpret_pointer_cast

From cppreference.com
 
 
 
 
std::experimental::shared_ptr
メンバ関数
非メンバ関数
experimental::static_pointer_castexperimental::dynamic_pointer_castexperimental::const_pointer_castexperimental::reinterpret_pointer_cast
std::shared_ptr と同一のメンバおよび非メンバ
 
template< class T, class U >

std::experimental::shared_ptr<T>

    static_pointer_cast( const std::experimental::shared_ptr<U>& r ) noexcept;
(1) (Library Fundamentals TS)
template< class T, class U >

std::experimental::shared_ptr<T>

    dynamic_pointer_cast( const std::experimental::shared_ptr<U>& r ) noexcept;
(2) (Library Fundamentals TS)
template< class T, class U >

std::experimental::shared_ptr<T>

    const_pointer_cast( const std::experimental::shared_ptr<U>& r ) noexcept;
(3) (Library Fundamentals TS)
template< class T, class U >

std::experimental::shared_ptr<T>

    reinterpret_pointer_cast( const std::experimental::shared_ptr<U>& r ) noexcept;
(4) (Library Fundamentals TS)

std::experimental::shared_ptr の新しいインスタンスを生成します。このインスタンスは、r の格納されているポインタをキャスト式で変換した結果のポインタを保持します。r が空の場合、新しい shared_ptr も空になります(ただし、その格納されているポインタが必ずしも null とは限りません)。

それ以外の場合、新しい shared_ptrr と所有権を共有します。ただし、dynamic_pointer_cast によって実行される dynamic_cast が null ポインタを返した場合、新しい shared_ptr は空になります。

Ytypename std::experimental::shared_ptr<T>::element_type とすると、結果として得られる std::experimental::shared_ptr の格納ポインタは、それぞれ次の順序で呼び出されることによって取得されます。

1) static_cast<Y*>(r.get())
2) dynamic_cast<Y*>(r.get())dynamic_cast の結果が null ポインタ値の場合、返される shared_ptr は空になります)。
3) const_cast<Y*>(r.get())
4) reinterpret_cast<Y*>(r.get())

これらの関数の動作は、対応する U* から T* へのキャストが正常に形成される場合を除き、未定義です。

1) static_cast<T*>((U*)nullptr) が正常に形成される場合を除き、動作は未定義です。
2) dynamic_cast<T*>((U*)nullptr) が正常に形成される場合を除き、動作は未定義です。
3) const_cast<T*>((U*)nullptr) が正常に形成される場合を除き、動作は未定義です。
4) reinterpret_cast<T*>((U*)nullptr) が正常に形成される場合を除き、動作は未定義です。

[編集] パラメータ

r - 変換するポインタ

[編集]

[編集] 関連項目

新しい shared_ptr を構築する
(public member function) [編集]
格納されたポインタにstatic_castdynamic_castconst_cast、またはreinterpret_castを適用する
(関数テンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)