Skip to content

Latest commit

 

History

History
75 lines (55 loc) · 2.92 KB

op_destructor.md

File metadata and controls

75 lines (55 loc) · 2.92 KB

デストラクタ

  • memory[meta header]
  • std[meta namespace]
  • out_ptr_t[meta class]
  • function[meta id-type]
  • cpp23[meta cpp]
~out_ptr_t();

概要

指定したSmart型スマートポインタに、レガシーC関数呼び出しにより取得されたポインタ値を格納する。

スマートポインタへのポインタ値格納には、Smart::reset()メンバ関数、もしくはSmartオブジェクト構築+ムーブ代入operator=が利用される。

  • オブジェクト単位でカスタムデリータを管理するstd::shared_ptr<T>の場合、out_ptr_tコンストラクタにてデリータオブジェクトを渡しておくことで、reset()呼び出しの取得ポインタ値に続く引数として渡される。 この動作はout_ptr_tクラステンプレートの適格要件にて強制される。
  • 型レベルでカスタムデリータを管理するstd::unique_ptr<T,D>の場合、reset()呼び出しには取得ポインタ値のみが渡される。
  • これ以外のスマートポインタ型では、同スマートポインタの動作セマンティクスに従う。

効果

説明用のSP型を下記の通り定義する :

  • Smart::pointerが有効な型名であればSmart::pointer
  • そうでなければ、Smart::element_type*が有効な型名であればSmart::element_type*
  • そうでなければ、pointer_traits<Smart>::element_type*
  • そうでなければ、Pointer

説明用メンバ変数s, a, pを用いて、以下と同じ効果を持つ :

  • s.reset(static_cast<SP>(p), std::forward<Args>(args)...) が適格ならば、

    if (p) {
      apply([&](auto&&... args) {
        s.reset(static_cast<SP>(p), std::forward<Args>(args)...); }, std::move(a));
    }
    • apply[link /reference/tuple/apply.md]
  • is_constructible_v<Smart, SP, Args...>trueならば、

    if (p) {
      apply([&](auto&&... args) {
        s = Smart(static_cast<SP>(p), std::forward<Args>(args)...); }, std::move(a));
    }
    • apply[link /reference/tuple/apply.md]
  • そうでなければ、プログラムは不適格となる。

バージョン

言語

  • C++23

処理系

関連項目

参照