The following code example is taken from the book
C++23 - The Complete Guide
by Nicolai M. Josuttis,
Leanpub, 2026
The code is licensed under a
Creative Commons Attribution 4.0 International License.
// raw code
#include <print>
#include <string>
#include <vector>
#include <list>
#include <ranges>
int main()
{
std::vector<std::string> vec{"tic", "tac", "toe"};
std::list lst = {47, 11, 0, 8, 15};
std::println("{}", vec);
std::println("{}\n", lst);
for (auto [name, val] : std::views::zip(vec, lst)) {
std::println("{}:{}", name, val);
}
std::println("");
for (auto [i, x, y] : std::views::zip(std::views::iota(1), vec, lst)) {
std::println("{}: {}/{}", i, x, y);
}
}