zip_view
is a range adaptor that takes one or more
view
s
, and produces a
view
whose
i
th element is a tuple-like value consisting of the
i
th
elements of all views. The size of produced view is the minimum of sizes of all adapted views.
zip_view
always models input_range
, and models forward_range
, bidirectional_range
, random_access_range
, or sized_range
if all adapted view
types model the corresponding concept.
zip_view
models common_range
if
common_range
, orbidirectional_range
, and every adapted view type models common_range
, orrandom_access_range
and sized_range
.The name views::zip
denotes a customization point object, which is a const function object of a literal semiregular
class type. See CustomizationPointObject for details.
views_
all adapted view objects
zip_view
sized_range
sized_range
or forward_range
std::ranges::view_interface<D>
) [edit] returns a constant iterator to the beginning of the range
std::ranges::view_interface<D>
) [edit] returns a sentinel for the constant iterator of the range
std::ranges::view_interface<D>
) [edit] returns whether the derived view is not empty, provided only if ranges::empty is applicable to it
std::ranges::view_interface<D>
) [edit] returns the first element in the derived view, provided if it satisfies forward_range
std::ranges::view_interface<D>
) [edit] returns the last element in the derived view, provided only if it satisfies bidirectional_range
and common_range
std::ranges::view_interface<D>
) [edit] returns the n
th element in the derived view, provided only if it satisfies random_access_range
std::ranges::view_interface<D>
) [edit] [edit] Deduction guides [edit] Nested classes the iterator type
zip_view
is not a common_range
This specialization of ranges::enable_borrowed_range makes zip_view
satisfy borrowed_range
when each underlying view satisfies it.
#include <array> #include <iostream> #include <list> #include <ranges> #include <string> #include <tuple> #include <vector> void print(auto const rem, auto const& range) { for (std::cout << rem; auto const& 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 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[edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4