std::ranges::cartesian_product_view<First, Vs...>::size
來自 cppreference.com
< cpp | ranges | 笛卡爾積檢視 (cartesian product view)
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); }
[編輯] 參見
(C++20) |
返回等於範圍大小的整數 (定製點物件) |
(C++20) |
返回等於範圍大小的有符號整數 (定製點物件) |