Open In App

std::rank in C++ with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

The std::rank template of C++ STL is present in the <type_traits> header file. The std::rank template of C++ STL is used to find the rank of type T. This function return the rank of type T.

Header File:

#include<type_traits>

Template Class:

template<class T>
struct rank;

template<class T>
inline constexpr
       std::size_t rank_v
        = rank<T>::value;

Syntax:

std::rank<T>::value

Parameter: The std::rank template accepts a single parameter T(Trait class) and returns the rank of it.

Return Value: The template std::rank return the rank of type T.

Below is the program to demonstrate std::rank:

Program:




// C++ program to illustrate std::rank
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
  
// Driver Code
int main()
{
  
    cout << "rank of following type:"
         << endl;
    cout << "int: "
         << rank<int>::value
         << endl;
  
    cout << "int[]: "
         << rank<int[]>::value
         << endl;
  
    cout << "int[][10]: "
         << rank<int[][10]>::value
         << endl;
  
    cout << "int[10][10]: "
         << rank<int[10][10]>::value
         << endl;
  
    return 0;
}


Output:

rank of following type:
int: 0
int[]: 1
int[][10]: 2
int[10][10]: 2

Reference: http://www.cplusplus.com/reference/type_traits/rank/


Last Updated : 08 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads