std:: remove_all_extents
From cppreference.net
C++
Metaprogramming library
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ヘッダーで定義
<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)
|
指定された次元に沿った配列型のサイズを取得する
(クラステンプレート) |
|
(C++11)
|
指定された配列型から1つの次元を除去する
(クラステンプレート) |