std::remove_extent
提供: cppreference.com
ヘッダ <type_traits> で定義 | ||
template<class T > struct remove_extent; | (C++11以上) | |
T
が何らかの型 X
の配列であれば、 X
に等しいメンバ型 type
が提供されます。 そうでなければ type
は T
です。 T が多次元配列の場合は、最初の次元のみが除去されることに注意してください。
目次 |
[編集]メンバ型
名前 | 定義 |
type | T の要素の型 |
[編集]ヘルパー型
template<class T > using remove_extent_t =typename remove_extent<T>::type; | (C++14以上) | |
[編集]実装例
template<class T>struct remove_extent {typedef T type;}; template<class T>struct remove_extent<T[]>{typedef T type;}; template<class T, std::size_t N>struct remove_extent<T[N]>{typedef T type;}; |
[編集]例
Run this code
#include <iostream>#include <iterator>#include <algorithm>#include <type_traits> template<class A>typenamestd::enable_if<std::rank<A>::value==1>::type print_1d(const A& a){ copy(a, a+std::extent<A>::value, std::ostream_iterator<typename std::remove_extent<A>::type>(std::cout, " "));std::cout<<'\n';} int main(){int a[][3]={{1,2,3},{4,5,6}};// print_1d(a); // compile-time error print_1d(a[1]);}
出力:
4 5 6
[編集]関連項目
(C++11) | 型が配列型かどうか調べます (クラステンプレート) |
(C++11) | 配列型の次元数を取得します (クラステンプレート) |
(C++11) | 配列型の指定された次元のサイズを取得します (クラステンプレート) |
(C++11) | 指定された配列型からすべてのエクステントを削除します (クラステンプレート) |