| ||||||||||||||||||||||
| Range primitives | |||||||
| |||||||
| Range concepts | |||||||||||||||||||
| |||||||||||||||||||
| Range factories | |||||||||
| |||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Helper items | |||||||||||||||||
| |||||||||||||||||
constexprauto size() requires(sized_range<Views>&& ...); | (1) | (since C++26) |
constexprauto size()const requires(sized_range<const Views>&& ...); | (2) | (since C++26) |
Returns the number of elements.
Equivalent toreturnstd::apply ( [](auto...sizes) { using CT=ranges::common_type_t<decltype(sizes)...>; return(make-unsigned-like-t <CT>(sizes)+ ...); }, tuple-transform (ranges::size, views_ ) );.
Contents |
As described above.
Constant.
The complexity ofconcat_view is constant time (even though in some cases it is a linear function of the number of ranges it concatenates which is a statically known parameter of this view) because time complexity as required by the ranges concepts are formally expressed with respect to the total number of elements (the size) of a given range, and not to the statically known parameters of that range.
The preliminary version can be checked out onCompiler Explorer.
#include <cassert>#include <forward_list>#include <list>#include <ranges> int main(){constexprstaticauto a={1,2};constexprstaticauto b={1,2,3};constexprstaticauto c={1,2,3,4}; constexprauto con{std::views::concat(a, b, c)}; static_assert(std::ranges::sized_range<decltype(con)>); static_assert(con.size()==2+3+4); std::forward_list d= b; static_assert(not std::ranges::sized_range<std::forward_list<int>>);constauto cat{std::views::concat(b, c, d)}; static_assert(not std::ranges::sized_range<decltype(cat)>);// auto x = cat.size(); // error: cat is not sized_range because of d std::list e= c;constauto dog{std::views::concat(a, b, e)}; static_assert(std::ranges::sized_range<decltype(dog)>);assert(dog.size()==2+3+4);}
(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] |