A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/type_traits/extent/ below:

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 type definition value_type A type capable of representing non-negative integer values type An instantiation of integral_constant
Member constants Inherited from integral_constant:
member constant definition value The extent of the Ith dimension of T
Member functions Inherited from integral_constant:
operator value_type
Returns value (public member function)

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
rank
Array rank (class template)
alignment_of
Alignment of (class template)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4