Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions docs/standard-library/rank-class.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,74 @@
---
description: "Learn more about: rank Class"
title: "rank Class"
ms.date: "11/04/2016"
title: "rank class"
description: "Learn more about: rank class"
ms.date: 08/28/2025
f1_keywords: ["type_traits/std::rank"]
helpviewer_keywords: ["rank class", "rank"]
ms.assetid: bc9f1b8f-800f-46ca-b6f4-d8579ed5406a
---
# rank Class
# `rank` class

Gets number of array dimensions.

## Syntax

```cpp
template <class Ty>
template <class Type>
struct rank;
```

### Parameters
### Template parameters

*Ty*\
*`Type`*\
The type to query.

## Remarks

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.
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.

## Example

```cpp
// std__type_traits__rank.cpp
// compile with: /EHsc

#include <type_traits>
#include <iostream>

int main()
{
{
std::cout << "rank<int> == "
<< std::rank<int>::value << std::endl;
std::cout << "rank<int[5]> == "
<< std::rank<int[5]>::value << std::endl;
std::cout << "rank<int[5][10]> == "
<< std::rank<int[5][10]>::value << std::endl;

return (0);
}
int single_dim_array[]{ 1, 2, 3 };
int double_dim_array[2][1]{ { 4 }, { 5 } };

std::cout << "\nrank<decltype(single_dim_array)> == "
<< std::rank<decltype(single_dim_array)>::value << std::endl;
std::cout << "rank<decltype(double_dim_array)> == "
<< std::rank<decltype(double_dim_array)>::value << std::endl;
}
```

```Output
rank<int> == 0
rank<int[5]> == 1
rank<int[5][10]> == 2

rank<decltype(single_dim_array)> == 1
rank<decltype(double_dim_array)> == 2
```

## Requirements

**Header:** \<type_traits>
**Header:** `<type_traits>`

**Namespace:** std
**Namespace:** `std`

## See also

[<type_traits>](../standard-library/type-traits.md)\
[extent Class](../standard-library/extent-class.md)
[`<type_traits>`](type-traits.md)\
[`extent` class](extent-class.md)