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

履歴 編集

concept
<concepts>

std::destructible(C++20)

namespace std {
  template <class T>
  concept destructible = is_nothrow_destructible_v<T>;
}

概要

destructibleは、任意の型Tが破棄可能であることを表すコンセプトである。

備考

デストラクタが実際に例外を投げる事はないが、noexcept(false)相当の指定がされているような場合でも、本コンセプトを満たす事は出来ない。

#include <iostream>
#include <concepts>
#include <vector>

template<std::destructible T>
void f(const char* name) {
  std::cout << name << " is destructible" << std::endl;
}

template<typename T>
void f(const char* name) {
  std::cout << name << " is not destructible" << std::endl;
}

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

struct S2 {
  ~S2() = delete;
};


int main() {
  f<int>("int");
  f<std::vector<int>>("std::vector<int>");
  f<S1>("S1");
  f<S2>("S2");
  f<void>("void");
}

出力

int is destructible
std::vector<int> is destructible
S1 is not destructible
S2 is not destructible
void is not destructible

バージョン

言語

  • C++20

処理系

関連項目

参照