Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::views::zip,std::ranges::zip_view

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
      std::ranges::zip_view
      Member functions
      Deduction guides
      Iterator
      Member functions
      Non-member functions
      Sentinel
      Member functions
      Non-member functions
       
      Defined in header<ranges>
      template<ranges::input_range...Views>

          requires(ranges::view<Views>&& ...)&&(sizeof...(Views)>0)
      class zip_view

         :publicranges::view_interface<zip_view<Views...>>
      (1)(since C++23)
      namespace views{

         inlineconstexpr/*unspecified*/ zip=/*unspecified*/;

      }
      (2)(since C++23)
      Call signature
      template<ranges::viewable_range...Rs>

          requires/* see below */

      constexprranges::viewauto zip( Rs&&...rs);
      (since C++23)
      1)zip_view is a range adaptor that takes one or moreviews, and produces aview whoseith element is a tuple-like value consisting of theith elements of all views. The size of produced view is the minimum of sizes of all adapted views.
      2)views::zip is a customization point object.

      When calling with no argument,views::zip() isexpression-equivalent toauto(views::empty<std::tuple<>>).

      Otherwise,views::zip(rs...) isexpression-equivalent toranges::zip_view<views::all_t<decltype((rs))>...>(rs...).

      zip_view always modelsinput_range, and modelsforward_range,bidirectional_range,random_access_range, orsized_range if all adaptedview types model the corresponding concept.

      zip_view modelscommon_range if

      Contents

      Customization point objects

      The nameviews::zip denotes acustomization point object, which is a constfunction object of aliteralsemiregular class type. SeeCustomizationPointObject for details.

      [edit]Data members

      Member Description
      std::tuple<Views...>views_ all adapted view objects
      (exposition-only member object*)

      [edit]Member functions

      constructs azip_view
      (public member function)[edit]
      returns an iterator to the beginning
      (public member function)[edit]
      returns an iterator or a sentinel to the end
      (public member function)[edit]
      returns the number of elements, provided only if each underlying (adapted) range satisfiessized_range
      (public member function)[edit]
      Inherited fromstd::ranges::view_interface
      returns whether the derived view is empty, provided only if it satisfiessized_range orforward_range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      (C++23)
      returns a constant iterator to the beginning of the range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      (C++23)
      returns a sentinel for the constant iterator of the range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns whether the derived view is not empty, provided only ifranges::empty is applicable to it
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns the first element in the derived view, provided if it satisfiesforward_range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns the last element in the derived view, provided only if it satisfiesbidirectional_range andcommon_range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns thenth element in the derived view, provided only if it satisfiesrandom_access_range
      (public member function ofstd::ranges::view_interface<D>)[edit]

      [edit]Deduction guides

      [edit]Nested classes

      the iterator type
      (exposition-only member class template*)
      the sentinel type used whenzip_view is not acommon_range
      (exposition-only member class template*)

      [edit]Helper templates

      template<class...Views>

      constexprbool enable_borrowed_range<ranges::zip_view<Views...>>=

         (ranges::enable_borrowed_range<Views>&& ...);
      (since C++23)

      This specialization ofranges::enable_borrowed_range makeszip_view satisfyborrowed_range when each underlying view satisfies it.

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_ranges_zip202110L(C++23)ranges::zip_view,
      ranges::zip_transform_view,
      ranges::adjacent_view,
      ranges::adjacent_transform_view

      [edit]Example

      Run this code
      #include <array>#include <iostream>#include <list>#include <ranges>#include <string>#include <tuple>#include <vector> void print(autoconst rem,autoconst& range){for(std::cout<< rem;autoconst& elem: range)std::cout<< elem<<' ';std::cout<<'\n';} int main(){auto x=std::vector{1,2,3,4};auto y=std::list<std::string>{"α","β","γ","δ","ε"};auto z=std::array{'A','B','C','D','E','F'};     print("Source views:","");    print("x: ", x);    print("y: ", y);    print("z: ", z);     print("\nzip(x,y,z):",""); for(std::tuple<int&,std::string&,char&> elem: std::views::zip(x, y, z)){std::cout<< std::get<0>(elem)<<' '<< std::get<1>(elem)<<' '<< std::get<2>(elem)<<'\n';         std::get<char&>(elem)+=('a'-'A');// modifies the element of z}     print("\nAfter modification, z: ", z);}

      Output:

      Source views:x: 1 2 3 4y: α β γ δ εz: A B C D E F zip(x,y,z):1 α A2 β B3 γ C4 δ D After modification, z: a b c d E F

      [edit]See also

      aview consisting of results of application of a transformation function to corresponding elements of the adapted views
      (class template)(customization point object)[edit]
      takes aview consisting oftuple-like values and a number N and produces aview of Nth element of each tuple
      (class template)(range adaptor object)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/zip_view&oldid=177009"

      [8]ページ先頭

      ©2009-2025 Movatter.jp