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

std::extent

Defined in header <type_traits>

template< class T, unsigned N = 0> struct extent;

(since C++11)

如果T是数组类型,提供成员常量。value的元素数等于N数组的第四维,如果N[0, std::rank<T>::value).任何其他类型,或T是沿其第一维的未知界数组,并且N是0,value是0。

辅助变量模板

template< class T, unsigned N = 0 > inline constexpr std::size_t extent_v = extent<T, N>::value;

(since C++17)

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

成员常数

value static

the number of elements along the Nth dimension of T (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>

可能的实施

模板<类T,无符号N=0>结构范围:std::整数[医]常数<std::size[医]t,0>{};模板<class T>结构范围<T。[],0>:std::整数[医]常数<std::size[医]t,0>{};模板<类T,无符号N>结构范围<T。[],N>:std::区段<T,N-1>{};模板<class T,std::size[医]结构范围<T我,0>:std::整数[医]常数<std::size[医]T,I>{};模板<类T,std::size[医]t i,无符号N>结构范围<T我,N>:STD::范围<T,N-1>{};

*。

二次

代码语言:javascript
复制
#include <iostream>
#include <type_traits>
 
int main()
{
    std::cout << std::extent<int[3]>::value << '\n'; //< default dimension is 0
    std::cout << std::extent<int[3][4], 0>::value << '\n';
    std::cout << std::extent<int[3][4], 1>::value << '\n';
    std::cout << std::extent<int[3][4], 2>::value << '\n';
    std::cout << std::extent<int[]>::value << '\n';
 
    const auto ext = std::extent<int[9]>{};
    std::cout << ext << '\n'; //< implicit conversion to std::size_t
 
    const int ints[] = {1,2,3,4};
    std::cout << std::extent<decltype(ints)>::value << '\n'; //< array size 
}

二次

产出:

二次

代码语言:javascript
复制
3
3
4
0
0
9
4

二次

另见

is_array (C++11)

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

rank (C++11)

obtains the number of dimensions of an array type (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。

扫码关注腾讯云开发者

领取腾讯云代金券