std::ranges...product_view(3)
π NAME π
okay bestie, we're reading the std::ranges...product_view(3) page from the C++ Standard Libary manual, and the main character is std::ranges::cartesian_product_view::cartesian_product_view β that's the constructor itself, no cap π
.
β¨ Synopsis β¨
here's the exact synopsis, bestie β two overloads, both constexpr, both since C++23:
constexpr cartesian_product_view() = default;
(1) (since C++23)
constexpr explicit cartesian_product_view( First first_base, Vs...
(2) (since C++23)
bases );
so this thing constructs an cartesian_product_view (yes, "an" is literally in the source, we're not fixing it π). lowkey straightforward:
- Default constructor. Default-initializes the underlying data member
base_. - Move constructs the underlying
base_by initializing it withstd::move(first_base),std::move(bases)....
π Parameters π
first_baseβ the first view object to adapt πΈbasesβ the pack of views objects to adapt π«Ά
π Example π
bestie, run this code and watch the cartesian product do its little dance β¨:
// Run this code
#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); // overload
(2)
for (int i{1}; auto const& [rx, ry, rz] : v)
std::cout << std::format("({} {} {}){}", rx, ry, rz, (i++ % 3)
? ' ' : '\n');
}
β¨ Output: β¨
and it prints exactly this, periodt:
(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)
source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::ranges...product_view(3) β love u, bye bestie! πβ¨
π¦ 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