std::extent() template in C++ with Examples
The std::is_const template of C++ STL is present in the <type_traits> header file. If A is an array that has a rank greater than B, the extent is the bound of the Ath dimension and if B is zero and A is the array of unknown bound, than the extent value is zero.
Header File:
#include<type_traits>
Syntax:
template
<class A, unsigned B = 0>
struct extent;
Parameters: It accepts the following parameters:
- A : It represents a particular type.
- B : It represents the dimensions for which the extent is to be obtained.
Below are the programs to demonstrate std::extent():
Program 1:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
int main()
{
cout << extent< int [3]>::value << endl;
cout << extent< int [3][4], 0>::value << endl;
cout << extent< int [3][4], 1>::value << endl;
cout << extent< int [3][4], 2>::value << endl;
cout << extent< int []>::value << endl;
const int ints[] = { 1, 2, 3, 4 };
cout << extent< decltype (ints)>::value
<< endl;
return 0;
}
|
Program 2:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
int main()
{
typedef int gfg[][50][70];
cout << "gfg array (int[][50][70]):" << endl;
cout << "rank: " << rank<gfg>::value << endl;
cout << extent<gfg, 0>::value << endl;
cout << extent<gfg, 1>::value << endl;
cout << extent<gfg, 2>::value << endl;
cout << extent<gfg, 3>::value << endl;
return 0;
}
|
Output:
gfg array (int[][50][70]):
rank: 3
0
50
70
0
Reference: http://www.cplusplus.com/reference/type_traits/extent/
Last Updated :
28 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...