Namespaces
Variants

std:: remove_extent

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
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_extent ;
(C++11以降)

T が何らかの型 X の配列である場合、 type X と等しいメンバ型定義として提供します。それ以外の場合、 type T となります。Tが多次元配列の場合、最初の次元のみが除去されることに注意してください。

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

目次

メンバー型

名前 定義
type T の要素の型

ヘルパー型

template < class T >
using remove_extent_t = typename remove_extent < T > :: type ;
(C++14以降)

実装例

template<class T>
struct remove_extent { using type = T; };
template<class T>
struct remove_extent<T[]> { using type = T; };
template<class T, std::size_t N>
struct remove_extent<T[N]> { using type = T; };

#include <algorithm>
#include <iostream>
#include <iterator>
#include <type_traits>
template<class A>
    std::enable_if_t<std::rank_v<A> == 1>
print_1d(const A& a)
{
    std::copy(a, a + std::extent_v<A>,
        std::ostream_iterator<std::remove_extent_t<A>>(std::cout, " "));
    std::cout << '\n';
}
int main()
{
    int a[][3] = {{1, 2, 3}, {4, 5, 6}};
//  print_1d(a); // コンパイル時エラー
    print_1d(a[1]);
}

出力:

4 5 6

関連項目

(C++11)
型が配列型かどうかをチェックする
(クラステンプレート)
(C++11)
配列型の次元数を取得する
(クラステンプレート)
(C++11)
指定された次元に沿った配列型のサイズを取得する
(クラステンプレート)
指定された配列型からすべての次元を除去する
(クラステンプレート)