std::ranges::slide_view<V>::size
From cppreference.com
< cpp | ranges | slide view
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Ranges library
(C++23)(C++23)
(C++26)(C++26)
(C++23)(C++23)
(C++26)(C++26)
(C++26)(C++26)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
std::ranges::slide_view
slide_view::size
(C++26)
Member functions
Non-member functions
Member functions
Non-member functions
constexpr auto size()
requires ranges::sized_range <V>;
(1)
(since C++23)
requires ranges::sized_range <V>;
constexpr auto size() const
requires ranges::sized_range <const V>;
(2)
(since C++23)
requires ranges::sized_range <const V>;
Returns the number of elements.
Let base_
and n_
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);
[edit] Return value
The number of elements. Equals to 0, if the number of elements (ranges::size (base_
)) in underlying view base_
is less than "window size" n_
.
[edit] Example
Run this code
#include <forward_list> #include <iostream> #include <list> #include <ranges> int main() { constexpr static auto v = {1, 2, 3, 4, 5, 6}; constexpr int width1{4}; constexpr auto view1{std::views::slide (v, width1)}; static_assert(view1.size() == 3); static_assert(view1.size() == (v.size() - width1 + 1)); constexpr int width2{8}; constexpr auto 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; const auto view3{std::views::slide (forward_list, width1)}; // auto x = view3.size(); // error: sized_range constraint is not satisfied std::list list = v; const auto view4{std::views::slide (list, width1)}; std::cout << view4.size() << '\n'; // prints 3 }
Output:
3