`
adjacent_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/adjacent_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  |  A  [ std::tuple ](/w/cpp/utility/tuple "cpp/utility/tuple") object  |  A template parameter   
[ ranges::  slide_view  ](http://en.cppreference.com/w/cpp/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_zip ` ](/w/cpp/feature_test#cpp_lib_ranges_zip "cpp/feature test") |  202110L  |  (C++23)  |  std::ranges::zip_view  ,   
std::ranges::zip_transform_view  ,  
` std::ranges::adjacent_view ` ,  
std::ranges::adjacent_transform_view  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/adjacent_view&action=edit&section=7 "Edit
section: Example") ]  Example

Run this code

    
    
    #include <array>
    #include <format>
    #include <iostream>
    #include <ranges>
    #include <tuple>
     
    int main()
    {
        constexpr [std::array](http://en.cppreference.com/w/cpp/container/array) v{1, 2, 3, 4, 5, 6};
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "v = [1 2 3 4 5 6]\n";
     
        for (int i{}; [std::tuple](http://en.cppreference.com/w/cpp/utility/tuple) t : v | std::views::adjacent<3>)
        {
            auto [t0, t1, t2] = t;
            [std::cout](http://en.cppreference.com/w/cpp/io/cout) << [std::format](http://en.cppreference.com/w/cpp/utility/format/format)("e = {:<{}}[{} {} {}]\n", "", 2 * i++, t0, t1, t2);
        }
    }

Output:

    
    
    v = [1 2 3 4 5 6]
    e = [1 2 3]
    e =   [2 3 4]
    e =     [3 4 5]
    e =       [4 5 6]

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

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

    

  * 26.7.25 Adjacent view [range.adjacent] 

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

[ ranges::adjacent_transform_view  views::adjacent_transform  ](/w/cpp/ranges/adjacent_transform_view "cpp/ranges/adjacent transform view") (C++23)  |  a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") consisting of tuples of results of application of a transformation function 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_transform_view&action=edit)  
---|---  
[ ranges::slide_view  views::slide  ](/w/cpp/ranges/slide_view "cpp/ranges/slide view") (C++23)  |  a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") whose M  th  element is a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") over the M  th  through (M + N - 1)  th  elements of another [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view")   
(class template)  (range adaptor object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_slide_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 "cpp/ranges/view") that are ` N ` -sized non-overlapping successive chunks of the elements of another [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view")   
(class template)