<type_traits>

class template
<type_traits>

std::extent

template <class T, unsigned I = 0> struct extent;
Array dimension extent

Trait class to obtain the extent of the Ith dimension of type T.

If T is an array that has a rank greater than I, the extent is the bound (i.e., the number of elements) of the Ith dimension.

In all other cases, and in the case that I is zero and T is an array of unknown bound, the extent value is zero.

This class is derived from integral_constant.

Template parameters

T
A type.
I
Dimension for which the extent is to be obtained. Indexing of dimensions is zero-based.
If omitted, this is 0 by default.

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 extent of the Ith dimension of T

Member functions

Inherited from integral_constant:

Example

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

int main() {
  typedef int mytype[][24][60];
  std::cout << "mytype array (int[][24][60]):" << std::endl;
  std::cout << "rank: " << std::rank<mytype>::value << std::endl;
  std::cout << "extent (0th dimension): " << std::extent<mytype,0>::value << std::endl;
  std::cout << "extent (1st dimension): " << std::extent<mytype,1>::value << std::endl;
  std::cout << "extent (2nd dimension): " << std::extent<mytype,2>::value << std::endl;
  std::cout << "extent (3rd dimension): " << std::extent<mytype,3>::value << std::endl;
  return 0;
}

Possible output:
mytype array (int[][24][60]):
rank: 3
extent (0th dimension): 0
extent (1st dimension): 24
extent (2nd dimension): 60
extent (3rd dimension): 0


See also