Skip to content

Latest commit

 

History

History
83 lines (64 loc) · 2.37 KB

destroy_at.md

File metadata and controls

83 lines (64 loc) · 2.37 KB

destroy_at

  • memory[meta header]
  • std[meta namespace]
  • function template[meta id-type]
  • cpp17[meta cpp]
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));
    • destroy[link destroy.md]
    • begin[link /reference/iterator/begin.md]
    • end[link /reference/iterator/end.md]
  • そうでない場合、以下と等価:

    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);
}
  • std::destroy_at[color ff0000]

出力

314

バージョン

言語

  • C++17

処理系

関連項目

参照