<type_traits>

類模板
<type_traits>

std::is_trivially_destructible

template <class T> struct is_trivially_destructible;
is trivially destructible

用於識別Tis a trivially destructible type.

Trivially destructible types include scalar types, trivially copy constructible classes and arrays of such types.

A trivially destructible class is a class (defined with, structor聯合體定義)
  • uses the implicitly defined destructor.
  • the destructor is not virtual.
  • its base class and non-static data members (if any) are themselves also trivially destructible types.

要放回的字元的is_trivially_destructible類繼承自integral_constant,其值為true_typefalse_type,取決於Tis trivially destructible.

模板引數

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

成員型別

Inherited from integral_constant
成員型別定義
value_typebool
型別true_type 或 false_type

成員常量

Inherited from integral_constant
成員常量定義
trueorfalse

成員函式

Inherited from integral_constant

示例

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

struct A { };
struct B { ~B(){} };

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

輸出
is_trivially_destructible:
int: true
A: true
B: false


另見