• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    class template
    <ranges>

    std::tuple_element

    namespace std {
      template<class I, class S, ranges::subrange_kind K>
      struct tuple_element<0, ranges::subrange<I, S, K>> {
        using type = I;
      };
    
      template<class I, class S, ranges::subrange_kind K>
      struct tuple_element<0, const ranges::subrange<I, S, K>> {
        using type = I;
      };
    
      template<class I, class S, ranges::subrange_kind K>
      struct tuple_element<1, ranges::subrange<I, S, K>> {
        using type = S;
      };
    
      template<class I, class S, ranges::subrange_kind K>
      struct tuple_element<1, const ranges::subrange<I, S, K>> {
        using type = S;
      };
    }
    

    概要

    tuple_elementは、タプルとして見なせる型から、I番目の要素型を取得するためのクラスである。

    <ranges>ヘッダでは、subrangeに関する特殊化を定義する。

    subrangeをタプルとして見たとき、大きさ2で、第0要素はイテレータ、第1要素は番兵である。

    #include <ranges>
    #include <concepts>
    
    int main()
    {
      constexpr std::ranges::subrange sub = std::views::empty<int>;
      static_assert(std::same_as<std::tuple_element_t<0, decltype(sub)>, std::ranges::iterator_t<decltype(sub)>>);
      static_assert(std::same_as<std::tuple_element_t<1, decltype(sub)>, std::ranges::sentinel_t<decltype(sub)>>);
    }
    

    出力

    バージョン

    言語

    • C++20

    処理系

    参照