Namespaces
Variants

std:: remove_all_extents

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
remove_all_extents
(C++11)

Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
ヘッダーで定義 <type_traits>
template < class T >
struct remove_all_extents ;
(C++11以降)

T が何らかの型 X の多次元配列である場合、 X と等しいメンバ型 type を提供します。それ以外の場合、 type T となります。

プログラムが std::remove_all_extents の特殊化を追加する場合、動作は未定義です。

目次

メンバー型

名前 定義
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 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)
指定された次元に沿った配列型のサイズを取得する
(クラステンプレート)
指定された配列型から1つの次元を除去する
(クラステンプレート)