Namespaces
Variants

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

ja.cppreference.net より
 
 
範囲ライブラリ
範囲アダプタ
 
 
ヘッダ <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 のサイズを取得する
(クラステンプレート特殊化)