Namespaces
Variants

std:: tuple_element <std::array>

From cppreference.net
헤더에 정의됨 <array>
template < std:: size_t I, class T, std:: size_t N >
struct tuple_element < I, std:: array < T, N > > ;
(C++11부터)

튜플과 유사한 인터페이스를 사용하여 배열 요소의 타입에 컴파일 타임 인덱스 접근을 제공합니다.

목차

멤버 타입

멤버 타입 정의
type 배열 요소의 타입

가능한 구현

template<std::size_t I, class T>
struct tuple_element;
template<std::size_t I, class T, std::size_t N>
struct tuple_element<I, std::array<T,N>>
{
    using type = T;
};

예제

#include <array>
#include <tuple>
#include <type_traits>
int main()
{
    // 배열을 정의하고 0번 위치의 요소 타입을 가져옴
    std::array<int, 10> data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    using T = std::tuple_element<0, decltype(data)>::type; // int
    static_assert(std::is_same_v<T, int>);
    const auto const_data = data;
    using CT = std::tuple_element<0, decltype(const_data)>::type; // const int
    // tuple_element의 결과는 튜플과 유사한 타입의 cv 한정자에 의존함
    static_assert(!std::is_same_v<T, CT>);
    static_assert(std::is_same_v<CT, const int>);
}

참고 항목

Structured binding (C++17) 지정된 이름들을 초기화자의 부분 객체나 튜플 요소에 바인딩합니다
지정된 요소의 타입을 얻습니다
(클래스 템플릿 특수화)
pair 의 요소 타입을 얻습니다
(클래스 템플릿 특수화)