From cppreference.com
constexprautosize()requiresranges::sized_range<V>; (1) (since C++20)constexprautosize()constrequiresranges::sized_range<constV>; (2) (since C++20)Let
be the underlying view,
be the stored count (the number passed to the constructor, or 0 if *this is default constructed). Equivalent to
constautos=ranges::size(
);
constautoc=static_cast<decltype(s)>(
);
returns<c?0:s-c;
Return value
The number of elements.
Example
Run this code
#include<array>#include<ranges>intmain(){constexprstd::arraya{42,43,44};static_assert(std::ranges::drop_view{std::views::all(a),0}.size()==3&&std::ranges::drop_view{std::views::all(a),1}.size()==2&&std::ranges::drop_view{std::views::all(a),2}.size()==1&&std::ranges::drop_view{std::views::all(a),3}.size()==0&&std::ranges::drop_view{std::views::all(a),4}.size()==0);}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)