"cpp/ranges/range") argument. 
  * ` T ` has exactly one public base class  ranges  ::  range_adaptor_closure  < T  > , and  T  has no base classes of type  ranges  ::  range_adaptor_closure  < U  > for any other type  U  . 
  * ` T ` does not satisfy [ ` range ` ](/w/cpp/ranges/range "cpp/ranges/range") . 

###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/range_adaptor_closure&action=edit&section=1
"Edit section: Example") ]  Example

Run this code

    
    
    #include <ranges>
    #include <string_view>
     
    // Define Slice as a range adaptor closure
    struct Slice : std::ranges::range_adaptor_closure<Slice>
    {
        [std::size_t](http://en.cppreference.com/w/cpp/types/size_t) start = 0;
        [std::size_t](http://en.cppreference.com/w/cpp/types/size_t) end = [std::string_view::npos](http://en.cppreference.com/w/cpp/string/basic_string_view/npos);
     
        constexpr [std::string_view](http://en.cppreference.com/w/cpp/string/basic_string_view) operator()([std::string_view](http://en.cppreference.com/w/cpp/string/basic_string_view) sv) const
        {
            return sv.substr(start, end - start);
        }
    };
     
    int main()
    {
        constexpr [std::string_view](http://en.cppreference.com/w/cpp/string/basic_string_view) str = "01234567";
     
        constexpr Slice slicer{.start = 1, .end = 6};
     
        constexpr auto sv1 = slicer(str); // use slicer as a normal function object
        constexpr auto sv2 = str | slicer; // use slicer as a range adaptor closure object
        static_assert(sv1 == "12345");
        static_assert(sv2 == "12345");
     
        // range adaptor closures can be composed
        constexpr auto slice_and_drop
            = slicer
            | std::[views::drop_while](http://en.cppreference.com/w/cpp/ranges/drop_while_view)([](char ch) { return ch != '3'; });
        static_assert([std::string_view](http://en.cppreference.com/w/cpp/string/basic_string_view)(str | slice_and_drop) == "345");
    }

Retrieved from " [
https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/range_adaptor_closure&oldid=159782
](https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/range_adaptor_closure&oldid=159782)
"

#####  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/range_adaptor_closure "A list of all wiki pages that link here \[j\]")
  * [ Related changes ](/w/Special:RecentChangesLinked/cpp/ranges/range_adaptor_closure "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/range_adaptor_closure&printable=yes "Printable version of this page \[p\]")
  * [ Permanent link ](/mwiki/index.php?title=cpp/ranges/range_adaptor_closure&oldid=159782 "Permanent link to this revision of the page")
  * [ Page information ](/mwiki/index.php?title=cpp/ranges/range_adaptor_closure&action=info)

  * In other languages 

  * [ Deutsch ](http://de.cppreference.com/w/cpp/ranges/range_adaptor_closure "cpp/ranges/range adaptor closure")
  * [ Español ](http://es.cppreference.com/w/cpp/ranges/range_adaptor_closure "cpp/ranges/range adaptor closure")
  * [ 日本語 ](http://ja.cppreference.com/w/cpp/ranges/range_adaptor_closure "cpp/ranges/range adaptor closure")
  * [ Русский ](http://ru.cppreference.com/w/cpp/ranges/range_adaptor_closure "cpp/ranges/range adaptor closure")
  * [ 中文 ](http://zh.cppreference.com/w/cpp/ranges/range_adaptor_closure "cpp/ranges/range adaptor closure")

  * This page was last modified on 28 September 2023, at 11:19. 
  * This page has been accessed 5,911 t