Namespaces
Variants

std:: tuple_element <std::ranges::subrange>

From cppreference.net
Ranges library
Range adaptors
헤더에 정의됨 <ranges>
template < class I, class S, ranges:: subrange_kind K >
struct tuple_element < 0 , ranges:: subrange < I, S, K >> ;
(1) (C++20부터)
template < class I, class S, ranges:: subrange_kind K >
struct tuple_element < 0 , const ranges:: subrange < I, S, K >> ;
(2) (C++20부터)
template < class I, class S, ranges:: subrange_kind K >
struct tuple_element < 1 , ranges:: subrange < I, S, K >> ;
(3) (C++20부터)
template < class I, class S, ranges:: subrange_kind K >
struct tuple_element < 1 , const ranges:: subrange < I, S, K >> ;
(4) (C++20부터)

std::tuple_element 의 부분 특수화는 std::ranges::subrange 에 대해 튜플과 유사한 구문을 사용하여 subrange 의 반복자 또는 센티널 타입에 대한 컴파일 타임 접근을 제공합니다. 이는 구조화된 바인딩 지원을 위해 제공됩니다.

1,2) 반복자 타입, 즉 I 를 획득합니다.
3,4) 센티넬 타입, 즉 S 를 획득합니다.

목차

멤버 타입

멤버 타입 정의
type (1,2) I
(3,4) S

참고 사항

get 함수들이 subrange 에 대해 반복자와 센티널을 값으로 반환하기 때문에, const 한정자가 subrange 가 const로 한정된 경우(단 volatile로 한정되지 않은 경우) 결과 타입에 추가되지 않습니다.

만약 subrange 가 volatile로 한정된 경우, volatile 또는 const volatile 타입에 대한 부분 특수화가 사용되기 때문에 결과 타입들도 volatile로 한정됩니다. 이러한 사용법은 더 이상 권장되지 않습니다.

예제

#include <iterator>
#include <list>
#include <ranges>
#include <type_traits>
int main()
{
    std::list<int> list{3, 1, 4, 1, 5, 9, 2, 6};
    std::ranges::subrange subrange
    {
        std::counted_iterator{std::begin(list), 4},
        std::default_sentinel
    };
    static_assert(
        std::is_same_v<
            std::tuple_element_t<0, decltype(subrange)>,
            // implementation-defined type:
            std::counted_iterator<std::_List_iterator<int>>
            >);
    static_assert(
        std::is_same_v<
            std::tuple_element_t<1, decltype(subrange)>,
            std::default_sentinel_t
            >);
}

참고 항목

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