<type_traits>

類模板
<type_traits>

std::rank

template <class T> struct rank;
Array rank

Trait class to obtain the rank of typeT.

The rank of an array type is its number of dimensions. For other types is zero.

The class is derived from integral_constant.

模板引數

T
一個型別。

成員型別

Inherited from integral_constant
成員型別定義
value_typeA type capable of representing non-negative integer values
型別An instantiation ofintegral_constant

成員常量

Inherited from integral_constant
成員常量定義
The rank ofT

成員函式

Inherited from integral_constant

示例

1
2
3
4
5
6
7
8
9
10
11
12
// array rank example
#include <iostream>
#include <type_traits>

int main() {
  std::cout << "rank:" << std::endl;
  std::cout << "int: " << std::rank<int>::value << std::endl;
  std::cout << "int[]: " << std::rank<int[]>::value << std::endl;
  std::cout << "int[][10]: " << std::rank<int[][10]>::value << std::endl;
  std::cout << "int[10][10]: " << std::rank<int[10][10]>::value << std::endl;
  return 0;
}

可能的輸出
rank:
int: 0
int[]: 1
int[][10]: 2
int[10][10]: 2


另見