From cppreference.com
Defined in header
template<ranges::input_range...Views>requires(ranges::view<Views>&&...)&&(sizeof...(Views)>0)classzip_view:publicranges::view_interface<zip_view<Views...>> (1) (since C++23)namespaceviews{inlineconstexpr/*unspecified*/zip=/*unspecified*/;} (2) (since C++23)Call signature
template<ranges::viewable_range...Rs>requires/* see below */constexprranges::viewautozip(Rs&&...rs);(since C++23)1)zip_view is a range adaptor that takes one or more
, and produces a
whose ith element is a tuple-like value consisting of the ith 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() is
to auto(views::empty<std::tuple<>>).
Otherwise, views::zip(rs...) is expression-equivalent to ranges::zip_view<views::all_t<decltype((rs))>...>(rs...).
zip_view always models
, and models
,
,
, or
if all adapted
types model the corresponding concept.
zip_view models
if
sizeof...(Views) is equal to 1, and the only adapted view type models
, or
at least one adapted view type does not model
, and every adapted view type models
, or
every adapted view type models both
and
.
Customization point objects
The name views::zip denotes a customization point object, which is a const
of a
class type. See
for details.
Data members
Member Description std::tuple<Views...>views_all adapted view objects
(exposition-only member object*)Member functions
constructs a zip_view
(public member function)
returns an iterator to the beginning
(public member function)
returns an iterator or a sentinel to the end
(public member function)
returns the number of elements, provided only if each underlying (adapted) range satisfies
(public member function)
Inherited from
returns whether the derived view is empty, provided only if it satisfies
or
(public member function of std::ranges::view_interface<D>)
(C++23)
returns a constant iterator to the beginning of the range
(public member function of std::ranges::view_interface<D>)
(C++23)
returns a sentinel for the constant iterator of the range
(public member function of std::ranges::view_interface<D>)
returns whether the derived view is not empty, provided only if
is applicable to it
(public member function of std::ranges::view_interface<D>)
returns the first element in the derived view, provided if it satisfies
(public member function of std::ranges::view_interface<D>)
returns the last element in the derived view, provided only if it satisfies
and
(public member function of std::ranges::view_interface<D>)
returns the nth element in the derived view, provided only if it satisfies
(public member function of std::ranges::view_interface<D>)
Nested classes
the iterator type
(exposition-only member class template*)the sentinel type used when zip_view is not a
(exposition-only member class template*)Helper templates
template<class...Views>constexprboolenable_borrowed_range<ranges::zip_view<Views...>>=(ranges::enable_borrowed_range<Views>&&...);(since C++23)This specialization of
makes
satisfy
when each underlying view satisfies it.
Notes
macroValueStdFeature
(C++23)ranges::zip_view,
ranges::zip_transform_view,
ranges::adjacent_view,
ranges::adjacent_transform_viewExample
Run this code
#include<array>#include<iostream>#include<list>#include<ranges>#include<string>#include<tuple>#include<vector>voidprint(autoconstrem,autoconst&range){for(std::cout<<rem;autoconst&elem:range)std::cout<<elem<<' ';std::cout<<'\n';}intmain(){autox=std::vector{1,2,3,4};autoy=std::list<std::string>{"α","β","γ","δ","ε"};autoz=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 4 y: α β γ δ ε z: A B C D E F zip(x,y,z): 1 α A 2 β B 3 γ C 4 δ D After modification, z: a b c d E F See also