定义于头文件
<type_traits>
|
||
template< class T >
struct remove_all_extents; |
(C++11 起) | |
若 T
是某类型 X
的多维数组,则提供等于 X
的成员 typedef type
,否则 type
为 T
。
目录 |
名称 | 定义 |
type
|
T 的元素类型
|
template< class T >
using remove_all_extents_t = typename remove_all_extents<T>::type; |
(C++14 起) | |
template<class T> struct remove_all_extents { typedef T type;}; template<class T> struct remove_all_extents<T[]> { typedef typename remove_all_extents<T>::type type; }; template<class T, std::size_t N> struct remove_all_extents<T[N]> { typedef typename remove_all_extents<T>::type type; }; |
#include <iostream> #include <type_traits> #include <typeinfo> template<class A> void foo(const A&) { typedef typename std::remove_all_extents<A>::type Type; std::cout << "underlying type: " << typeid(Type).name() << '\n'; } int main() { float a1[1][2][3]; int a2[3][2]; float a3[1][1][1][1][2]; double a4[2][3]; foo(a1); foo(a2); foo(a3); foo(a4); }
输出:
underlying type: f underlying type: i underlying type: f underlying type: d
(C++11)
|
检查类型是否是数组类型 (类模板) |
(C++11)
|
获取数组类型的维数 (类模板) |
(C++11)
|
获取数组类型在指定维度的大小 (类模板) |
(C++11)
|
从给定数组类型移除一个维度 (类模板) |