std::ranges::chunk_view<V>::size
来自 cppreference.cn
< cpp | ranges | chunk view
constexpr auto size() requires ranges::sized_range<V>; |
(1) | (自 C++23 起) |
constexpr auto size() const requires ranges::sized_range<const V>; |
(2) | (自 C++23 起) |
返回元素的数量,它是不小于底层视图 base_
的大小除以底层数据成员 n_
的商的最小整数值,后者保存传递给构造函数的数字(如果是默认构造,则为 0)。等效于 return
to-unsigned-like
(div-ceil
(ranges::distance(base_
),
n_
)); 。
[edit] 返回值
元素的数量。
[edit] 示例
运行此代码
#include <ranges> int main() { constexpr static auto v = {1, 2, 3, 4, 5}; constexpr auto w{ std::ranges::chunk_view(v, 2) }; static_assert(w.size() == (5 / 2 + (5 % 2 ? 1 : 0))); }
[edit] 参见
(C++20) |
返回等于范围大小的整数 (自定义点对象) |
(C++20) |
返回等于范围大小的有符号整数 (自定义点对象) |