|
1 | 1 | --- |
2 | | -description: "Learn more about: rank Class" |
3 | | -title: "rank Class" |
4 | | -ms.date: "11/04/2016" |
| 2 | +title: "rank class" |
| 3 | +description: "Learn more about: rank class" |
| 4 | +ms.date: 08/28/2025 |
5 | 5 | f1_keywords: ["type_traits/std::rank"] |
6 | 6 | helpviewer_keywords: ["rank class", "rank"] |
7 | | -ms.assetid: bc9f1b8f-800f-46ca-b6f4-d8579ed5406a |
8 | 7 | --- |
9 | | -# rank Class |
| 8 | +# `rank` class |
10 | 9 |
|
11 | 10 | Gets number of array dimensions. |
12 | 11 |
|
13 | 12 | ## Syntax |
14 | 13 |
|
15 | 14 | ```cpp |
16 | | -template <class Ty> |
| 15 | +template <class Type> |
17 | 16 | struct rank; |
18 | 17 | ``` |
19 | 18 |
|
20 | | -### Parameters |
| 19 | +### Template parameters |
21 | 20 |
|
22 | | -*Ty*\ |
| 21 | +*`Type`*\ |
23 | 22 | The type to query. |
24 | 23 |
|
25 | 24 | ## Remarks |
26 | 25 |
|
27 | | -The type query holds the value of the number of dimensions of the array type *Ty*, or 0 if *Ty* is not an array type. |
| 26 | +The type query holds the value of the number of dimensions of the array type *`Type`*, or 0 if *`Type`* is not an array type. |
28 | 27 |
|
29 | 28 | ## Example |
30 | 29 |
|
31 | 30 | ```cpp |
32 | 31 | // std__type_traits__rank.cpp |
33 | 32 | // compile with: /EHsc |
| 33 | + |
34 | 34 | #include <type_traits> |
35 | 35 | #include <iostream> |
36 | 36 |
|
37 | 37 | int main() |
38 | | - { |
| 38 | +{ |
39 | 39 | std::cout << "rank<int> == " |
40 | 40 | << std::rank<int>::value << std::endl; |
41 | 41 | std::cout << "rank<int[5]> == " |
42 | 42 | << std::rank<int[5]>::value << std::endl; |
43 | 43 | std::cout << "rank<int[5][10]> == " |
44 | 44 | << std::rank<int[5][10]>::value << std::endl; |
45 | 45 |
|
46 | | - return (0); |
47 | | - } |
| 46 | + int single_dim_array[]{ 1, 2, 3 }; |
| 47 | + int double_dim_array[2][1]{ { 4 }, { 5 } }; |
| 48 | + |
| 49 | + std::cout << "\nrank<decltype(single_dim_array)> == " |
| 50 | + << std::rank<decltype(single_dim_array)>::value << std::endl; |
| 51 | + std::cout << "rank<decltype(double_dim_array)> == " |
| 52 | + << std::rank<decltype(double_dim_array)>::value << std::endl; |
| 53 | +} |
48 | 54 | ``` |
49 | 55 |
|
50 | 56 | ```Output |
51 | 57 | rank<int> == 0 |
52 | 58 | rank<int[5]> == 1 |
53 | 59 | rank<int[5][10]> == 2 |
| 60 | +
|
| 61 | +rank<decltype(single_dim_array)> == 1 |
| 62 | +rank<decltype(double_dim_array)> == 2 |
54 | 63 | ``` |
55 | 64 |
|
56 | 65 | ## Requirements |
57 | 66 |
|
58 | | -**Header:** \<type_traits> |
| 67 | +**Header:** `<type_traits>` |
59 | 68 |
|
60 | | -**Namespace:** std |
| 69 | +**Namespace:** `std` |
61 | 70 |
|
62 | 71 | ## See also |
63 | 72 |
|
64 | | -[<type_traits>](../standard-library/type-traits.md)\ |
65 | | -[extent Class](../standard-library/extent-class.md) |
| 73 | +[`<type_traits>`](type-traits.md)\ |
| 74 | +[`extent` class](extent-class.md) |
0 commit comments