std::ranges::cartesian_product_view<First, Vs...>::size
来自cppreference.com
| |
(1) | (C++23 起) |
| |
(2) | (C++23 起) |
返回元素的个数。返回类型是实现定义的 /*unsigned-integer-like*/ 类型 U。
令 base_ 为底层的视图元组,并令 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);
}
参阅
(C++20) |
返回等于范围大小的整数 (定制点对象) |
(C++20) |
返回等于范围大小的有符号整数 (定制点对象) |