std::remove_all_extents
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <type_traits> で定義
|
||
template< class T > struct remove_all_extents; |
(C++11以上) | |
T が何らかの型 X の多次元配列であれば、 X と等しいメンバ型 type が提供されます。 そうでなければ、 type は T です。
メンバ型
| 名前 | 定義 |
type
|
T の要素の型
|
ヘルパー型
<tbody> </tbody> 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;
};
|
例
Run this code
#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) |
指定された配列型からエクステントを1つ削除します (クラステンプレート) |