std::remove_extent
返回数组降低一个维度后的数据类型。不改变数据类型的限制属性(const, volatile, const volatile)
一维数组降低到0维度;
二维数组降低到一维数组;
三维数组降低到二维数组;
std::extent
返回数组第一个维度的长度
std::remove_all_extents
返回数组的实际类型, int[] -> int, int[][2] -> int, int[][3][4] -> int
int arrO[] = { 1,2,3,4 };
int arrT[2][3] = { {1,2,3},{3,4,5} };
std::remove_extent<decltype(arrO)>::type oa{}; // int
std::remove_extent<decltype(arrT)>::type ob{}; // int[3]
cout << std::extent<decltype(arrO)>::value << endl; // 4, 一维数组的长度
cout << std::extent<decltype(arrT)>::value << endl; // 2 , 二维数组的第一维度的长度
const int arrF[3] = {};
const int arrS[4][3] = { {1,2,3},{4,5,6} };
std::remove_extent<decltype(arrF)>::type oc{}; // const int
std::remove_extent<decltype(arrS)>::type od{}; // const int[3]
cout << std::extent<decltype(arrF)>::value << endl; // 3
cout << std::extent<decltype(arrS)>::value << endl; // 4
volatile int arrD[] = { 1,2 };
volatile int arrE[][2] = { {1,2},{3,4}, { 5,6 } };
std::remove_extent<decltype(arrD)>::type oe{}; // volatile int
std::remove_extent<decltype(arrE)>::type of{}; // volatile int[2]
cout << std::extent<decltype(arrD)>::value << endl; // 2
cout << std::extent<decltype(arrE)>::value << endl; // 3
const volatile int arrQ[] = { 1,2 };
const volatile int arrP[][3] = { {1,2,3},{4,5,6} };
std::remove_extent<decltype(arrQ)>::type og{}; // const volatile int
std::remove_extent<decltype(arrP)>::type oh{}; // const volatile int[3]
cout << std::extent<decltype(arrQ)>::value << endl; // 2
cout << std::extent<decltype(arrP)>::value << endl; // 2
std::rank
返回数组的维度
int arr[] = { 1,2 };
int arrA[][3] = { {1,2,3} };
int arrB[1][2][3] = {};
std::rank<decltype(arr)>::value << endl; // 1, 一维数组
std::rank<decltype(arrA)>::value << endl; // 2 , 二维数组
std::rank<decltype(arrB)>::value << endl; // 3 , 三维数组
template<class _Ty, _Ty _Val>
struct integral_constant
{
static constexpr _Ty value = _Val;
using value_type = _Ty;
using type = integral_constant;
// intergral_constant可以像int一样使用
constexpr operator value_type() const noexcept
{
return (value);
}
// intergral_constant可以像int一样使用
constexpr value_type operator()() const noexcept
{
return (value);
}
};