Namespaces
Variants

std::ranges::chunk_view<V>:: size

From cppreference.net
Ranges library
Range adaptors
std::ranges::chunk_view
Member functions
chunk_view::size
Classes for input_range s
Deduction guides
outer-iterator
outer-iterator ::value_type
inner-iterator
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_ ) ) ;

返回值

元素数量。

示例

#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)));
}

参见

返回等于范围大小的整数值
(定制点对象)
返回等于范围大小的有符号整数值
(定制点对象)