std::ranges::cartesian_product_view<First, Vs...>::cartesian_product_view
来自cppreference.com
< cpp | ranges | cartesian product view
constexpr cartesian_product_view() = default; |
(1) | (C++23 起) |
constexpr explicit cartesian_product_view( First first_base, Vs... bases ); |
(2) | (C++23 起) |
参数
first_base | - | 用于适配的首个视图对象。 |
bases | - | 用于适配的视图对象的包。 |
示例
运行此代码
#include <array> #include <format> #include <iostream> #include <ranges> #include <vector> int main() { auto x = std::array{'A', 'B'}; auto y = std::vector{1, 2, 3}; auto z = std::vector{-1, -2, -3}; auto v = std::ranges::cartesian_product_view(x, y, z); // 重载 (2) for (int i{1}; auto const& [rx, ry, rz] : v) std::cout << std::format("({} {} {}){}", rx, ry, rz, (i++ % 3) ? ' ' : '\n'); }
输出:
(A 1 -1) (A 1 -2) (A 1 -3) (A 2 -1) (A 2 -2) (A 2 -3) (A 3 -1) (A 3 -2) (A 3 -3) (B 1 -1) (B 1 -2) (B 1 -3) (B 2 -1) (B 2 -2) (B 2 -3) (B 3 -1) (B 3 -2) (B 3 -3)