From cppreference.com
constexpr/*make-unsigned-like-t*/<std::iter_difference_t<I>>size()constrequires(K==ranges::subrange_kind::sized);(since C++20)Obtains the number of elements in the
:
If
is true, returns
.
Otherwise, returns
(
-
).
For the definition of /*make-unsigned-like-t*/, see
.
Return value
As described above.
Example
Run this code
#include<functional>#include<print>#include<ranges>#include<utility>intmain(){constautov={2,2,2,7,1,1,1,1,8,2,2,2,2,2};// the value type of views::chunk_by is the ranges::subrangeautoto_pair=[](autosub){returnstd::make_pair(sub[0],sub.size());};/* ^^^^ */autopairs=v|std::views::chunk_by(std::equal_to{})|std::views::transform(to_pair);std::println("{}",pairsbitorstd::views::keys);std::println("{}",pairsbitorstd::views::values);}Output:
[2, 7, 1, 8, 2] [3, 1, 4, 1, 5] See also
checks whether the subrange is empty
(public member function)
(C++17)(C++20)
returns the size of a container or array
(function template)
(C++20)
returns an integer equal to the size of a range
(customization point object)