std::ranges...es::zip_view(3)
π NAME π
Bestie, this page comes from the C++ Standard Libary manual, and the header energy is std::ranges...es::zip_view(3). The actual main characters are std::ranges::views::zip,std::ranges::zip_view π
πΈ Synopsis πΈ
Defined in header <ranges>:
template< ranges::input_range... Views >
requires (ranges::view<Views> && ...) && (sizeof...(Views) > 0)
class zip_view
: public ranges::view_interface<zip_view<Views...>>
(1) (since C++23)
namespace views {
inline constexpr /*unspecified*/ zip = /*unspecified*/;
}
(2) (since C++23)
Call signature
template< ranges::viewable_range... Rs >
requires /* see below */
constexpr auto zip( Rs&&... rs );
(since C++23)
zip_viewis a range adaptor that takes one or more views, 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.views::zipis a customization point object.
When calling with no argument, views::zip() is expression-equivalent 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 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:
sizeof...(Views)is equal to1, and the only adapted view type modelscommon_range, or- at least one adapted view type does not model
bidirectional_range, and every adapted view type modelscommon_range, or - every adapted view type models both
random_access_rangeandsized_range.
π«Ά Member functions π«Ά
constructorβ constructs azip_view.(C++23)(public member function)beginβ returns an iterator to the beginning.(C++23)(public member function)endβ returns an iterator or a sentinel to the end.(C++23)(public member function)sizeβ returns the number of elements. Provided only if each underlying (adapted) range satisfiessized_range.(C++23)(public member function)
π Inherited from std::ranges::view_interface π
emptyβ returns whether the derived view is empty. Provided if it satisfiessized_rangeorforward_range.(C++20)(public member function ofstd::ranges::view_interface<D>)cbeginβ returns a constant iterator to the beginning of the range.(C++23)(public member function ofstd::ranges::view_interface<D>)cendβ returns a sentinel for the constant iterator of the range.(C++23)(public member function ofstd::ranges::view_interface<D>)operator boolβ returns whether the derived view is not empty. Provided ifranges::emptyis applicable to it.(C++20)(public member function ofstd::ranges::view_interface<D>)frontβ returns the first element in the derived view. Provided if it satisfiesforward_range.(C++20)(public member function ofstd::ranges::view_interface<D>)backβ returns the last element in the derived view. Provided if it satisfiesbidirectional_rangeandcommon_range.(C++20)(public member function ofstd::ranges::view_interface<D>)operator[]β returns the n^th element in the derived view. Provided if it satisfiesrandom_access_range.(C++20)(public member function ofstd::ranges::view_interface<D>)
π Deduction guides π
The page gives this its own heading moment, but no extra details are listed here. Quiet slay, honestly π
π¦ Nested classes π¦
iteratorβ the iterator type.(C++23)(exposition-only member class template*)sentinelβ the sentinel type used whenzip_viewis not acommon_range.(C++23)(exposition-only member class template*)
β¨ Helper templates β¨
template< class... Views >
inline constexpr bool
enable_borrowed_range<ranges::zip_view<Views...>> =
(ranges::enable_borrowed_range<Views> && ...);
(since C++23)
This specialization of ranges::enable_borrowed_range makes zip_view satisfy borrowed_range when each underlying view satisfies it.
π Notes π
- Feature-test macro:
__cpp_lib_ranges_zipβ value:202110L; std:(C++23); feature:std::ranges::zip_view,std::ranges::zip_transform_view,std::ranges::adjacent_view,std::ranges::adjacent_transform_view.
β Example β
// Run this code
#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
π See also π
ranges::zip_transform_view,views::zip_transformβ a view consisting of tuples of results of application of a transformation function to corresponding elements of the adapted views.(C++23)(class template) (customization point object)ranges::elements_view,views::elementsβ takes a view consisting of tuple-like values and a numberNand produces a view ofN^th element of each tuple.(C++20)(class template) (range adaptor object)
π source/version: http://cppreference.com Β· date: 2024.06.10 Β· manual: std::ranges...es::zip_view(3) β mwah, thatβs the whole page, bestie. Go zip your faves together and be iconic π
β¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms