<type_traits>

類模板
<type_traits>

std::is_trivially_copy_constructible

template <class T> struct is_trivially_copy_constructible;
是否可平凡複製構造

用於識別T是一個可平凡複製構造的型別。

一個可平凡複製構造型別是指一個型別,它可以從相同型別的值或引用進行平凡構造。這包括標量型別可平凡複製構造類及其陣列。

一個可平凡複製構造類是一個類(使用, struct聯合體定義)
  • 隱式定義的複製建構函式
  • 沒有虛成員。
  • 其基類和非靜態資料成員(如果有)也都是可平凡複製構造型別

要放回的字元的is_trivially_copy_constructible類繼承自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_trivially_copy_constructible example
#include <iostream>
#include <type_traits>

struct A { };
struct B { B(const B&){} };
struct C { virtual void fn() {} };

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

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


另見