Namespaces
Variants

std::ranges::cartesian_product_view<First, Vs...>:: size

From cppreference.net
Ranges library
Range adaptors
constexpr /* 见说明 */ size ( )
requires /*cartesian-product-is-sized*/ < First, Vs... > ;
(1) (C++23 起)
constexpr /* 见说明 */ size ( ) const
requires /*cartesian-product-is-sized*/ < const First, const Vs... > ;
(2) (C++23 起)

返回元素数量。返回类型是实现定义的 /*unsigned-integer-like*/ 类型 U

bases_ 为底层的视图元组,且 prod bases_ 中所有范围大小的乘积。

1,2) 返回 prod 。如果 prod 无法用返回类型 U 表示,则行为未定义。

等价于:

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)>{});

目录

参数

(无)

返回值

元素数量,即所有底层范围大小的乘积。

注释

返回类型是最小的 /*unsigned-integer-like*/ 类型,该类型具有足够的宽度来存储所有底层范围最大尺寸的乘积(如果存在这样的类型)。

示例

#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);
}

参见

返回等于范围大小的整数值
(定制点对象)
返回等于范围大小的有符号整数值
(定制点对象)