p://en.cppreference.com/w/cpp/ranges/borrowed_range) < V  > ;  |  |  (since C++23)   
---|---|---  
|  |   
  
This specialization of [ ` ranges::enable_borrowed_range `
](/w/cpp/ranges/borrowed_range "cpp/ranges/borrowed range") makes ` slide_view
` satisfy [ ` borrowed_range ` ](/w/cpp/ranges/borrowed_range
"cpp/ranges/borrowed range") when the underlying view satisfies it.

###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/slide_view&action=edit&section=6 "Edit
section: Notes") ]  Notes

There are similarities between  ranges::adjacent_view  and  ranges::slide_view
:

  * Both create a "sliding window" of size ` _N_ ` . 
  * Both have the same size  ` _S - N + 1_ ` , where ` _S_ ` is the size of an adapted [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") such that  ` _S >= N > 0 _ ` . 

The differences between these adapters are:

View adaptor  |  ` value_type ` |  The window size ` _N_ `  
---|---|---  
[ ranges::  adjacent_view  ](http://en.cppreference.com/w/cpp/ranges/adjacent_view) |  A  [ std::tuple ](/w/cpp/utility/tuple "cpp/utility/tuple") object  |  A template parameter   
ranges  ::  slide_view  |  A [ ` range ` ](/w/cpp/ranges/range "cpp/ranges/range") |  A runtime parameter   
[ Feature-test ](/w/cpp/utility/feature_test "cpp/utility/feature test") macro  |  Value  |  Std  |  Feature   
---|---|---|---  
[ ` __cpp_lib_ranges_slide ` ](/w/cpp/feature_test#cpp_lib_ranges_slide "cpp/feature test") |  202202L  |  (C++23)  |  ` std::ranges::slide_view `  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/slide_view&action=edit&section=7 "Edit
section: Example") ]  Example

Run this code

    
    
    #include <algorithm>
    #include <iostream>
    #include <ranges>
     
    auto print_subrange = [](std::[ranges::viewable_range](http://en.cppreference.com/w/cpp/ranges/viewable_range) auto&& r)
    {
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '[';
        for (char space[]{0,0}; auto elem : r)
            [std::cout](http://en.cppreference.com/w/cpp/io/cout) << space << elem, *space = ' ';
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "] ";
    };
     
    int main()
    {
        const auto v = {1, 2, 3, 4, 5, 6};
     
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "All sliding windows of width:\n";
        for (const unsigned width : std::[views::iota](http://en.cppreference.com/w/cpp/ranges/iota_view)(1U, 1U + v.size()))
        {
            auto const windows = v | std::views::slide(width);
            [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "W = " << width << ": ";
            std::[ranges::for_each](http://en.cppreference.com/w/cpp/algorithm/ranges/for_each)(windows, print_subrange);
            [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '\n';
        }
    }

Output:

    
    
    All sliding windows of width W:
    W = 1: [1] [2] [3] [4] [5] [6] 
    W = 2: [1 2] [2 3] [3 4] [4 5] [5 6] 
    W = 3: [1 2 3] [2 3 4] [3 4 5] [4 5 6] 
    W = 4: [1 2 3 4] [2 3 4 5] [3 4 5 6] 
    W = 5: [1 2 3 4 5] [2 3 4 5 6] 
    W = 6: [1 2 3 4 5 6]

###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/slide_view&action=edit&section=8 "Edit
section: References") ]  References

  * C++23 standard (ISO/IEC 14882:2023): 

    

  * 26.7.29 Slide view [range.slide] 

###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/slide_view&action=edit&section=9 "Edit
section: See also") ]  See also

[ ranges::adjacent_view  views::adjacent  ](/w/cpp/ranges/adjacent_view "cpp/ranges/adjacent view") (C++23)  |  a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") consisting of tuples of references to adjacent elements of the adapted view   
(class template)  (range adaptor object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_adjacent_view&action=edit)  
---|---  
[ ranges::chunk_view  views::chunk  ](/w/cpp/ranges/chunk_view "cpp/ranges/chunk view") (C++23)  |  a range of [ ` view ` s ](/w/cpp/ranges/view "cp