remove_all_extents

remove_all_extents (모든 차원 제거)

std::remove_all_extents는 주어진 타입이 다차원 배열일 때 모든 배열 차원을 제거하고 요소 타입을 얻어내는 C++ 표준 라이브러리 템플릿이에요. 배열이 아닌 타입에 대해서는 원래 타입을 그대로 type으로 제공해요. C++11부터 사용할 수 있어요.

출처: cppreference

본문

<type_traits> 헤더에 정의되어 있어요.

템플릿 선언
template < class T > struct remove_all_extents ; (since C++11)

T가 어떤 타입 X의 다차원 배열이라면 멤버 typedef type은 X가 돼요. 그렇지 않으면 type은 T예요.

프로그램에서 std::remove_all_extents에 대한 특수화를 추가하면 동작이 정의되지 않아요.

멤버 타입

이름 설명
type T의 요소 타입

헬퍼 타입

템플릿 별칭
template < class T > using remove_all_extents_t = typename remove_all_extents < T >:: type ; (since 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

같이 보기

is_array (C++11) 타입이 배열 타입인지 확인해요 (클래스 템플릿)
rank (C++11) 배열 타입의 차원 수를 구해요 (클래스 템플릿)
extent (C++11) 배열 타입의 특정 차원 크기를 구해요 (클래스 템플릿)
remove_extent (C++11) 주어진 배열 타입에서 한 차원을 제거해요 (클래스 템플릿)
remove_all_extents (C++26) 반영된 배열 타입에서 모든 차원을 제거해요 (함수)

더 알아보기 (Learn more)

cppreference