std::remove_all_extents

定义于头文件 <type_traits>
template< class T >
struct remove_all_extents;
(C++11 起)

T 是某类型 X 的多维数组,则提供等于 X 的成员 typedef type ,否则 typeT

目录

成员类型

名称 定义
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)
获取数组类型在指定维度的大小
(类模板)
从给定数组类型移除一个维度
(类模板)

版本历史

  • (当前 | 先前 2017年7月25日 (二) 05:36Fruderica讨论 | 贡献. . (1,703字节) (-326). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 18:18P12bot讨论 | 贡献 . . (2,029字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 11:54P12bot讨论 | 贡献 . . (2,029字节) (-139). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 14:12P12bot讨论 | 贡献 . . (2,168字节) (+289). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 12:43P12讨论 | 贡献 . . (1,879字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (1,879字节) (-41). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 04:09P12讨论 | 贡献 . . (1,920字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (1,920字节) (+1,920). . (Translated from the English version using Google Translate)