<type_traits>

類模板
<type_traits>

std::is_array

template <class T> struct is_array;
陣列型別

識別 T 是否為陣列型別的特性類。

它繼承自 integral_constant,並根據T是陣列型別。

請注意,array 類模板的例項化不被此函式視為陣列型別,只有那些使用方括號([])內建語言語法宣告的才算。

模板引數

T
一個型別。

成員型別

繼承自 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
// is_array example
#include <iostream>
#include <array>
#include <string>
#include <type_traits>

int main() {
  std::cout << std::boolalpha;
  std::cout << "is_array:" << std::endl;
  std::cout << "int: " << std::is_array<int>::value << std::endl;
  std::cout << "int[3]: " << std::is_array<int[3]>::value << std::endl;
  std::cout << "array<int,3>: " << std::is_array<std::array<int,3>>::value << std::endl;
  std::cout << "string: " << std::is_array<std::string>::value << std::endl;
  std::cout << "string[3]: " << std::is_array<std::string[3]>::value << std::endl;
  return 0;
}

輸出
is_array:
int: false
int[3]: true
array<int,3>: false
string: false
string[3]: true


另見