std::ranges::zip_view<Views...>::size
來自 cppreference.com
constexpr auto size() requires (ranges::sized_range<Views> && ...); |
(1) | (C++23 起) |
constexpr auto size() const requires (ranges::sized_range<const Views> && ...); |
(2) | (C++23 起) |
返回 zip_view
中的元素數量。僅在每個底層(已適配的)range 滿足 sized_range
時提供此函式。
等價於
return std::apply ( [](auto... sizes) { using CT = /*make-unsigned-like-t*/<std::common_type_t<decltype(sizes)...>>; return ranges::min({CT(sizes)...}); }, /*tuple-transform*/(ranges::size, views_) );
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
元素數量,即所有已適配 view
s 大小中的最小值。
[編輯] 示例
執行此程式碼
#include <algorithm> #include <cassert> #include <deque> #include <forward_list> #include <ranges> #include <vector> int main() { auto x = std::vector{1, 2, 3, 4, 5}; auto y = std::deque{'a', 'b', 'c'}; auto z = std::forward_list{1., 2.}; auto v1 = std::views::zip(x, y); assert(v1.size() == std::min(x.size(), y.size())); assert(v1.size() == 3); [[maybe_unused]] auto v2 = std::views::zip(x, z); // auto sz = v2.size(); // Error, v2 does not have size(): static_assert(not std::ranges::sized_range<decltype(z)>); }
[編輯] 參閱
(C++20) |
返回等於範圍大小的整數 (定製點物件) |
(C++20) |
返回等於範圍大小的有符號整數 (定製點物件) |