<type_traits>

類模板
<type_traits>

std::is_compound

template <class T> struct is_compound;
Is compound type

Trait class that identifies whether T is a compound type.

它繼承自 integral_constant,並根據Tis a compound type (i.e., not a fundamental type).

這是一個複合型別特徵,其行為與以下程式碼相同:
1
2
template<class T>
struct is_compound : std::integral_constant <bool,!is_fundamental<T>::value> {};

模板引數

T
一個型別。

成員型別

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
// is_compound example
#include <iostream>
#include <type_traits>

int main() {
  std::cout << std::boolalpha;
  std::cout << "is_compound:" << std::endl;
  std::cout << "long int: " << std::is_compound<long int>::value << std::endl;
  std::cout << "float: " << std::is_compound<float>::value << std::endl;
  std::cout << "float*: " << std::is_compound<float*>::value << std::endl;
  std::cout << "float&: " << std::is_compound<float&>::value << std::endl;
  std::cout << "decltype(nullptr): " << std::is_compound<decltype(nullptr)>::value << std::endl;
  return 0;
}

輸出
is_compound:
long int: false
float: false
float*: true
float&: true
decltype(nullptr): false


另見