std:: remove_extent
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_extent ; |
(C++11부터) | |
만약
T
가 어떤 타입
X
의 배열이라면,
type
멤버 typedef를
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)
|
지정된 차원을 따라 배열 타입의 크기를 구합니다
(클래스 템플릿) |
|
(C++11)
|
주어진 배열 타입에서 모든 차원을 제거합니다
(클래스 템플릿) |