fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<class T>
  5. struct my_rank{
  6. static constexpr unsigned value = 0;
  7. };
  8. template<class T, unsigned I>
  9. struct my_rank<T[I]>{
  10. static constexpr unsigned value = my_rank<T>::value + 1;
  11. };
  12.  
  13. int main() {
  14. int a3[3][3][3];
  15. int a2[3][3];
  16. int a7[3][3][3][3][3][3][3];
  17. std::cout << my_rank<decltype(a3)>::value << std::endl;//3
  18. std::cout << my_rank<decltype(a2)>::value << std::endl;//2
  19. std::cout << my_rank<decltype(a7)>::value << std::endl;//7
  20. std::cout << my_rank<decltype(a3[0][0][0])>::value << std::endl;//0
  21. return 0;
  22. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
3
2
7
0