std::remove_all_extents
來自 cppreference.com
定義於標頭檔案 <type_traits> |
||
template< class T > struct remove_all_extents; |
(C++11 起) | |
如果 T
是某種型別 X
的多維陣列,則提供成員 typedef type
等於 X
;否則 type
是 T
。
如果程式為 std::remove_all_extents
新增特化,則行為未定義。
目錄 |
[編輯] 成員型別
名稱 | 定義 |
型別
|
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 info(const A&) { typedef typename std::remove_all_extents<A>::type Type; std::cout << "underlying type: " << typeid(Type).name() << '\n'; } int main() { float a0; float a1[1][2][3]; float a2[1][1][1][1][2]; float* a3; int a4[3][2]; double a5[2][3]; struct X { int m; } x0[3][3]; info(a0); info(a1); info(a2); info(a3); info(a4); info(a5); info(x0); }
可能的輸出
underlying type: float underlying type: float underlying type: float underlying type: float* underlying type: int underlying type: double underlying type: main::X
[編輯] 參閱
(C++11) |
檢查型別是否為陣列型別 (類模板) |
(C++11) |
獲取陣列型別的維數 (類模板) |
(C++11) |
獲取陣列型別在指定維度上的大小 (類模板) |
(C++11) |
從給定陣列型別中移除一個維度 (類模板) |