ranges/cartesianproductview.cpp
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
<vector>
#include
<list>
#include
<ranges>
int
main()
{
std::vector<std::string> rg1{
"tic"
,
"tac"
,
"toe"
};
std::vector rg2{1, 2};
std::list rg3{
'x'
,
'y'
,
'z'
};
std::println(
"{}"
, rg1);
std::println(
"{}"
, rg2);
std::println(
"{}"
, rg3);
for
(
auto
[v, s, c] : std::views::cartesian_product(rg1, rg2, rg3)) {
std::println(
"{}:{}:{}"
, v, s, c);
}
}