最終更新日時(UTC):
が更新

履歴 編集

function template
<memory>

std::destroy_at(C++17)

namespace std {
  template <class T>
  void destroy_at(T* location);           // (1) C++17

  template <class T>
  constexpr void destroy_at(T* location); // (1) C++20
}

概要

デストラクタを呼び出す。

この関数は、配置newで構築したオブジェクトを破棄するために使用する。

効果

  • Tが配列型である場合、以下と等価:

    destroy(begin(*location), end(*location));
    

  • そうでない場合、以下と等価:

    location->~T();
    

備考

#include <iostream>
#include <memory>

int main()
{
  // 配置newでオブジェクトを構築
  char storage[4];
  int* n = new(storage) int;

  *n = 314;
  std::cout << *n << std::endl;

  // デストラクタを呼び出して破棄
  std::destroy_at(n);
}

出力

314

バージョン

言語

  • C++17

処理系

関連項目

参照