首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::rank

Defined in header <type_traits>

template< class T > struct rank;

(since C++11)

如果T是数组类型,提供成员常量。value等于数组的维数。对于任何其他类型,value是0。

辅助变量模板

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

(since C++17)

继承自STD:积分[医]常量

成员常数

value static

the number of dimensions of T or zero (public static member constant)

成员函数

operator std::size_t

converts the object to std::size_t, returns value (public member function)

operator() (C++14)

returns value (public member function)

成员类型

Type

Definition

value_type

std::size_t

type

std::integral_constant<std::size_t, value>

可能的实施

模板<class T>结构等级:公共STD::整数[医]常数<std::size[医]t,0>{};模板<class T>结构秩<T。[]>:公共性病::整数[医]常数<std::size[医]T级<T>*值+1>{};模板<类T,std::size[医]t N>结构秩<Tn>:公共科技促进发展::整体[医]常数<std::size[医]T级<T>*值+1>{};

*。

二次

代码语言:javascript
复制
#include <iostream>
#include <type_traits>
 
int main()
{
    std::cout << std::rank<int[1][2][3]>::value << '\n';
    std::cout << std::rank<int[][2][3][4]>::value << '\n';
    std::cout << std::rank<int>::value << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
3
4
0

二次

另见

is_array (C++11)

checks if a type is an array type (class template)

extent (C++11)

obtains the size of an array type along a specified dimension (class template)

remove_extent (C++11)

removes one extent from the given array type (class template)

remove_all_extents (C++11)

removes all extents from the given array type (class template)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券