std::ranges::stride_view<V>::size
来自cppreference.com
< cpp | ranges | stride view
constexpr auto size() requires ranges::sized_range<V>; |
(C++23 起) | |
constexpr auto size() const requires ranges::sized_range<const V>; |
(C++23 起) | |
返回元素数量。
令 base_
为底层视图,并令 stride_
为存储的步长值。等价于:
return /*to-unsigned-like*/(/*div-ceil*/(ranges::distance(base_), stride_));
参数
(无)
返回值
元素的数量。返回值的计算如同表达式
(ranges::size(base_) / stride_) + ((ranges::size(base_) % stride_ ? 1 : 0)
示例
运行此代码
#include <forward_list> #include <ranges> int main() { namespace vs = std::views; constexpr static auto v = {1, 2, 3, 4, 5}; static_assert ( vs::stride(v, 1).size() == 5 and vs::stride(v, 2).size() == 3 and vs::stride(v, 3).size() == 2 and vs::stride(v, 4).size() == 2 and vs::stride(v, 5).size() == 1 and vs::stride(v, 6).size() == 1 ); std::forward_list list{v}; // auto s = vs::stride(list, 2).size(); // 错误:不是 sized_range }
参阅
(C++20) |
返回等于范围大小的整数 (定制点对象) |
(C++20) |
返回等于范围大小的有符号整数 (定制点对象) |