std::ranges...t_view::size(3)
std::ranges::cartesian_product_view::size(3) π
okay bestie, this is the glow-up of the C++ Standard Libary manual page for std::ranges::cartesian_product_view::size β section (3), no cap. It's the size() member of cartesian_product_view, and yes we're keeping every little detail. π
π NAME
std::ranges::cartesian_product_view::sizeβ literallystd::ranges::cartesian_product_view::size. That's the whole name, bestie. β¨
β¨ Synopsis
Here's the signature slate, copied exactly β including the (1) and (2) tags and the requires clauses. Don't come for me about the line breaks, they're part of the original vibe:
constexpr /* see description */ size()
(1) (since C++23)
requires __cartesian_product_is_sized<First, Vs...>;
constexpr /* see description */ size() const
requires __cartesian_product_is_sized<const First, const
(2) (since C++23)
Vs...>;
okay so what does it do? It returns the number of elements. The return type is an implementation-defined unsigned-integer-like type U. π«Ά
Let bases_ be the underlying tuple of views, and prod be the product of the sizes of all the ranges in bases_.
1,2) returns prod. β οΈ The behavior is undefined if prod cannot be represented by the return type U. Like, actually undefined, bestie β do not go there in production π.
Equivalent to:
return [&]<std::size_t... Is>(std::index_sequence<Is...>)
{
auto prod = static_cast<U>(1);
prod = (static_cast<U>(ranges::size(std::get<Is>(bases_))) * ...);
return prod;
}
(std::make_index_sequence<1U + sizeof...(Vs)>{});
πΈ Parameters
(none)β no parameters. Zero. Nada. The function takes nothing, and honestly? iconic. π
π¦ Return value
The number of elements, that is, the product of the sizes of all the underlying ranges. Slay. β¨
π Notes
The return type is the smallest unsigned-integer-like type that is sufficiently wide to store the product of the maximum sizes of all the underlying ranges, if such a type exists. That's the whole note, bestie. π«Ά
π₯ Example
Run this code, it's cute:
// Run this code
#include <ranges>
int main()
{
constexpr static auto w = {1};
constexpr static auto x = {2, 3};
constexpr static auto y = {4, 5, 6};
constexpr static auto z = {7, 8, 9, 10, 11, 12, 13};
constexpr auto v = std::ranges::cartesian_product_view(w, x, y, z);
static_assert(v.size() == w.size() * x.size() * y.size() * z.size()
and v.size() == 42);
}
π See also
ranges::sizeβ returns an integer equal to the size of a range.(C++20)(customization point object)β¨ranges::ssizeβ returns a signed integer equal to the size of a range.(C++20)(customization point object)π
okay bye bestie, hope this ate π
β source/version: http://cppreference.com Β· date: 2024.06.10 Β· footer page label: std::ranges...t_view::size(3) π
π¦ 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