<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


另见