From cppreference.com
constexprautosize()requiresranges::sized_range<V>;(since C++23)constexprautosize()constrequiresranges::sized_range<constV>;(since C++23)Returns the number of elements.
Let
be the underlying view and
be the stored stride value. Equivalent to:
return/*to-unsigned-like*/(/*div-ceil*/(ranges::distance(base_),stride_));Parameters
(none)
Return value
The number of elements. The returned value is calculated as if by expression
(ranges::size(base_)/stride_)+((ranges::size(base_)%stride_?1:0).
Example
Run this code
#include<forward_list>#include<ranges>intmain(){namespacevs=std::views;constexprstaticautov={1,2,3,4,5};static_assert(vs::stride(v,1).size()==5andvs::stride(v,2).size()==3andvs::stride(v,3).size()==2andvs::stride(v,4).size()==2andvs::stride(v,5).size()==1andvs::stride(v,6).size()==1);std::forward_listlist{v};// auto s = vs::stride(list, 2).size(); // Error: not a sized_range}See also
(C++20)
returns an integer equal to the size of a range
(customization point object)
(C++20)
returns a signed integer equal to the size of a range
(customization point object)