On this page
std::ranges::slide_view<V>::slide_view
|
(since C++23) |
Constructs a slide_view
initializing the underlying data members:
Parameters
base | - | the source view |
n | - | the "sliding window" size |
Example
#include <algorithm>
#include <iostream>
#include <ranges>
int main()
{
const auto source = {1, 2, 3, 4};
auto slide = std::views::slide(source, 3);
std::ranges::for_each(slide, [](std::ranges::viewable_range auto&& w)
{
std::cout << '[' << w[0] << ' ' << w[1] << ' ' << w[2] << "]\n";
});
}
Output:
[1 2 3]
[2 3 4]
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/ranges/slide_view/slide_view