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

履歴 編集

class template
<type_traits>

std::is_nothrow_destructible(C++11)

namespace std {
  template <class T>
  struct is_nothrow_destructible;

  template <class T>
  inline constexpr bool is_nothrow_destructible_v
    = is_nothrow_destructible<T>::value;          // C++17
}

概要

Tが破棄でき、かつそのデストラクタが例外を投げないか調べる

要件

Tは完全型であるか、const/volatile修飾された(あるいはされていない)voidか、要素数不明の配列型でなければならない。

効果

is_nothrow_destructibleは、型Tが例外を投げない保証のもとに破棄可能であるならばtrue_typeから派生し、そうでなければfalse_typeから派生する。

#include <type_traits>

struct X {
  ~X() {} // noexcept(true)
};

struct Y {
  ~Y() noexcept {}
};

struct Z {
  ~Z() noexcept(false) {}
};

static_assert(
  std::is_nothrow_destructible<int>::value == true,
  "int is nothrow destructible");

static_assert(
  std::is_nothrow_destructible<X>::value == true,
  "X is nothrow destructible");

static_assert(
  std::is_nothrow_destructible<Y>::value == true,
  "Y is nothrow destructible");

static_assert(
  std::is_nothrow_destructible<Z>::value == false,
  "Z isn't nothrow destructible");

int main() {}

出力

バージョン

言語

  • C++11

処理系

  • Clang: 3.0
  • GCC: 4.8.1
  • Visual C++: 2012, 2013, 2015
    • 2012は、正しく実装されていない。常にtrue_typeになっている。

参照