| ||||||||||||||||||||||
| Range primitives | |||||||
| |||||||
| Range concepts | |||||||||||||||||||
| |||||||||||||||||||
| Range factories | |||||||||
| |||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Helper items | |||||||||||||||||
| |||||||||||||||||
| Member functions | ||||
slide_view::size | ||||
(C++26) | ||||
| Deduction guides | ||||
| Iterator | ||||
| Member functions | ||||
| Non-member functions | ||||
| Sentinel | ||||
| Member functions | ||||
| Non-member functions | ||||
constexprauto size() requiresranges::sized_range<V>; | (1) | (since C++23) |
constexprauto size()const requiresranges::sized_range<const V>; | (2) | (since C++23) |
Returns the number of elements.
Letbase_ andn_ be the underlying view and “window size” respectively. Equivalent to
auto sz=ranges::distance(base_)- n_+1;if(sz<0) sz=0;return/*to-unsigned-like*/(sz);
The number of elements. Equals to0, if the number of elements (ranges::size(base_)) in underlying viewbase_ is less than “window size”n_.
#include <forward_list>#include <iostream>#include <list>#include <ranges> int main(){constexprstaticauto v={1,2,3,4,5,6}; constexprint width1{4};constexprauto view1{std::views::slide(v, width1)}; static_assert(view1.size()==3); static_assert(view1.size()==(v.size()- width1+1)); constexprint width2{8};constexprauto view2{std::views::slide(v, width2)};// window is too wide, so view2 has no elements: static_assert(view2.size()==0); std::forward_list forward_list= v;constauto view3{std::views::slide(forward_list, width1)};// auto x = view3.size(); // error: sized_range constraint is not satisfied std::list list= v;constauto view4{std::views::slide(list, width1)};std::cout<< view4.size()<<'\n';// prints 3}
Output:
3
(C++20) | returns an integer equal to the size of a range (customization point object)[edit] |
(C++20) | returns a signed integer equal to the size of a range (customization point object)[edit] |