std::ranges::cartesian_product_view<首先,Vs...>::大小
来自 zh.cppreference.net
constexpr /* see description */ size()
requires /*cartesian-product-is-sized*/<First, Vs...>;
|
(1) | (C++23 起) |
constexpr /* see description */ 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); }
参见
|
(C++20)
|
返回等于范围大小的整数值
(定制点对象) |
|
(C++20)
|
返回等于范围大小的有符号整数值
(定制点对象) |