Talk:cpp/ranges/zip view
From cppreference.com
< Talk:cpp
Stanislaw (talk) 10:22, 24 November 2022 (PST) Stanislaw
Example from : [1]
#include <list> #include <array> #include <tuple> #include <ranges> #include <vector> #include <string> #include <iostream> 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); }
Error:
main.cpp: In function ‘int main()’: main.cpp:26:67: error: ‘zip’ is not a member of ‘std::views’ 26 | for (std::tuple<int&, std::string&, char&> elem : std::views::zip(x, y, z)) { | ^~~
Compiler GCC v12.1 C++23
Can somebody help with issue where is zip?
Thank's
- Right, views::zip is not implemented in the online gcc-12.1. This is why we sometimes provide temporary links to Compiler Explorer, like this, so the users can check out the examples online.
Extended content |
---|
Eventually, the situation may become even better if Compiler Explorer be attached to cppreference directly, to enjoy the latest gcc/clang/msvc... versions with all the most recent features on. |
- --Space Mission (talk) 11:07, 24 November 2022 (PST)