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
            >);
}

関連項目

構造化バインディング (C++17) 指定された名前を初期化子のサブオブジェクトまたはタプルの要素にバインドする
タプルライクな型の要素型を取得する
(クラステンプレート)
std::ranges::subrange のサイズを取得する
(クラステンプレート特殊化)