<type_traits>

類模板
<type_traits>

std::is_destructible

template <class T> struct is_destructible;
是否可析構

用於識別T是一個可析構型別。

可析構型別 包括 標量型別可析構類

一個可析構類 是一個其解構函式不是被刪除的、並且可能在派生類中可訪問的類,並且其基類和所有非靜態資料成員本身也是可析構的。

要放回的字元的is_destructible類繼承自integral_constant,其值為true_typefalse_type,取決於T是可析構的。

模板引數

T
一個完整型別,或者void(可能帶 cv 限定),或者一個未知邊界的陣列。

成員型別

繼承自 integral_constant
成員型別定義
value_typebool
型別true_type 或 false_type

成員常量

繼承自 integral_constant
成員常量定義
truefalse

成員函式

繼承自 integral_constant

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// is_destructible example
#include <iostream>
#include <type_traits>

struct A { };
struct B { ~B() = delete; };
struct C : B {};

int main() {
  std::cout << std::boolalpha;
  std::cout << "is_destructible:" << std::endl;
  std::cout << "int: " << std::is_destructible<int>::value << std::endl;
  std::cout << "A: " << std::is_destructible<A>::value << std::endl;
  std::cout << "B: " << std::is_destructible<B>::value << std::endl;
  std::cout << "C: " << std::is_destructible<C>::value << std::endl;
  return 0;
}

輸出
is_destructible:
int: true
A: true
B: false
C: false


另見