std::remove_all_extents
From cppreference.com
| ヘッダ <type_traits> で定義 |
||
| template< class T > struct remove_all_extents; |
(C++11以降) | |
Tが何らかの型Xの多次元配列である場合、メンバ型typeをXに等しく提供します。それ以外の場合、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) |
指定された次元に沿った配列型のサイズを取得する (クラステンプレート) |
| (C++11) |
与えられた配列型から1つの次元を削除する (クラステンプレート) |