std::ranges::slide_view<V>::slide_view

From cppreference.com
< cpp‎ | ranges‎ | slide view
 
 
Ranges library
Range access
Range conversions
(C++23)
Range primitives



Dangling iterator handling
Range concepts
Views

Range factories
Range adaptors
Range generators
Range adaptor objects
Range adaptor closure objects
Helper items
(until C++23)(C++23)


 
 
constexpr explicit slide_view( V base, ranges::range_difference_t<V> n );
(since C++23)

Constructs a slide_view initializing the underlying data members:

  • move construct the underlying view base_ with std::move(base),
  • the "window size" n_ with n.

Parameters

base - the source view
n - the "sliding window" size

Example

A link to test: Compiler Explorer.

#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]