名稱空間
變體
操作

std::remove_all_extents

來自 cppreference.com
< cpp‎ | 型別
 
 
超程式設計庫
型別特性
型別類別
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11) 
(C++11)
(C++11)
型別屬性
(C++11)
(C++11)
(C++14)
(C++11)(C++26 中已棄用)
(C++11)(直到 C++20*)
(C++11)(C++20 中已棄用)
(C++11)
型別特性常量
元函式
(C++17)
支援的操作
關係與屬性查詢
型別修改
(C++11)(C++11)(C++11)
remove_all_extents
(C++11)

型別轉換
(C++11)(C++23 中已棄用)
(C++11)(C++23 中已棄用)
(C++11)
(C++11)(直到 C++20*)(C++17)

(C++11)
(C++17)
編譯時有理數算術
編譯時整數序列
 
定義於標頭檔案 <type_traits>
template< class T >
struct remove_all_extents;
(C++11 起)

如果 T 是某種型別 X 的多維陣列,則提供成員 typedef type 等於 X;否則 typeT

如果程式為 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)
獲取陣列型別在指定維度上的大小
(類模板) [編輯]
從給定陣列型別中移除一個維度
(類模板) [編輯]