std::ranges::adjacent_view<V,N>::size
来自cppreference.com
< cpp | ranges | adjacent view
constexprauto size() requires ranges::sized_range<V>; | (C++23 起) | |
constexprauto size()const requires ranges::sized_range<const V>; | (C++23 起) | |
返回元素的数量。
令 base_
为底层视图。等价于:
using SizeType = decltype(ranges::size(base_));using CommonType =ranges::common_type_t<SizeType, std::size_t>;auto size =static_cast<CommonType>(ranges::size(base_)); size -=std::min<CommonType>(size, N -1);returnstatic_cast<SizeType>(size);
目录 |
[编辑]参数
(无)
[编辑]返回值
元素的数量,当 ranges::size(base_) 小于 N 值时可能为 0。
[编辑]示例
运行此代码
#include <ranges> int main(){constexprstaticauto v ={1, 2, 3, 4, 5, 6}; constexprint width1 {4};constexprauto view1 {std::views::adjacent<width1>(v)}; static_assert(view1.size()==3); static_assert(view1.size()==(v.size()- width1 +1)); constexprint width2 {8};constexprauto view2 {std::views::adjacent<width2>(v)};// 窗口过宽,所以 view2 无元素: static_assert(view2.size()==0);}
[编辑]参阅
(C++20) | 返回等于范围大小的整数 (定制点对象) |
(C++20) | 返回等于范围大小的有符号整数 (定制点对象) |