{
            auto v = [std::vector](http://en.cppreference.com/w/cpp/container/vector){1, 2, 3, 1, 2, 3, 3, 3, 1, 2, 3};
            auto fun = std::[ranges::less](http://en.cppreference.com/w/cpp/ranges-functional-placeholder/less){};
            auto view = v | std::views::chunk_by(fun);
            print_chunks(view);
        }
        {
            auto v = [std::vector](http://en.cppreference.com/w/cpp/container/vector){1, 2, 3, 4, 4, 0, 2, 3, 3, 3, 2, 1};
            auto fun = [std::not_fn](http://en.cppreference.com/w/cpp/utility/functional/not_fn)(std::[ranges::equal_to](http://en.cppreference.com/w/cpp/ranges-functional-placeholder/equal_to){}); // or ranges::not_equal_to
            auto view = v | std::views::chunk_by(fun);
            print_chunks(view);
        }
        {
            [std::string](http://en.cppreference.com/w/cpp/string/basic_string) v = "__cpp_lib_ranges_chunk_by";
            auto fun = [](char x, char y) { return not(x == '_' or y == '_'); };
            auto view = v | std::views::chunk_by(fun);
            print_chunks(view, "");
        }
    }

Output:

    
    
    [1, 2, 3] [1, 2, 3] [3] [3] [1, 2, 3] 
    [1, 2, 3, 4] [4, 0, 2, 3] [3] [3, 2, 1] 
    [_] [_] [cpp] [_] [lib] [_] [ranges] [_] [chunk] [_] [by]

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

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

    

  * 26.7.30 Chunk by view [range.chunk.by] 

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

[ 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)  (range adaptor object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_chunk_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::stride_view  views::stride  ](/w/cpp/ranges/stride_view "cpp/ranges/stride view") (C++23)  |  a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") consisting of elements of another [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") , advancing over N elements at a time   
(class template)  (range adaptor object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_stride_view&action=edit)  
  
Retrieved from " [
https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/chunk_by_view&oldid=160898
](https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/chunk_by_view&oldid=160898)
"

#####  Navigation

  * [ Support us ](http://www.cppreference.com/support)
  * [ Recent changes ](/w/Special:RecentChanges "A list of recent changes in the wiki \[r\]")
  * [ FAQ ](/w/Cppreference:FAQ)
  * [ Offline version ](/w/Cppreference:Archives)

#####  Toolbox

  * [ What links here ](/w/Special:WhatLinksHere/cpp/ranges/chunk_by_view "A list of all wiki pages that link here \[j\]")
  * [ Related changes ](/w/Special:RecentChangesLinked/cpp/ranges/chunk_by_view "Recent changes in pages linked from this page \[k\]")
  * [ Upload file ](http://upload.cppreference.com/w/Special:Upload "Upload files \[u\]")
  * [ Special pages ](/w/Special:SpecialPages "A list of all special pages \[q\]")
  * [ Printable version ](/mwiki/index.php?title=cpp/ranges/chunk_by_view&prin