class template
<type_traits>

std::rank

template <class T> struct rank;
Array rank

Trait class to obtain the rank of type T.

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

The class inherits from integral_constant*.

* On most implementations (no standard specification).

Template parameters

T
A type.

Member types

Inherited from integral_constant:
member typedefinition
value_typeA type capable of representing non-negative integer values
typeAn instantiation of integral_constant

Member constants

Inherited from integral_constant:
member constantdefinition
valueThe rank of T

Member functions

Inherited from integral_constant:

Example

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;
}


Possible output:
rank:
int: 0
int[]: 1
int[][10]: 2
int[10][10]: 2

See also

<type_traits>