yRange<T, N>> = false;
     
    template<typename T, [std::size_t](http://en.cppreference.com/w/cpp/types/size_t) N>
    struct MyBorrowedRange : [std::span](http://en.cppreference.com/w/cpp/container/span)<T, N> {};
     
    template<typename T, [std::size_t](http://en.cppreference.com/w/cpp/types/size_t) N>
    inline constexpr bool std::ranges::enable_borrowed_range<MyBorrowedRange<T, N>> = true;
     
    int main()
    {
        static_assert(std::[ranges::range](http://en.cppreference.com/w/cpp/ranges/range)<MyRange<int, 8>>);
        static_assert(std::ranges::borrowed_range<MyRange<int, 8>> == false);
        static_assert(std::[ranges::range](http://en.cppreference.com/w/cpp/ranges/range)<MyBorrowedRange<int, 8>>);
        static_assert(std::ranges::borrowed_range<MyBorrowedRange<int, 8>> == true);
     
        auto getMyRangeByValue = []{ return MyRange<int, 4>{{1, 2, 42, 3}}; };
        auto dangling_iter = std::[ranges::max_element](http://en.cppreference.com/w/cpp/algorithm/ranges/max_element)(getMyRangeByValue());
        static_assert([std::is_same_v](http://en.cppreference.com/w/cpp/types/is_same)<std::[ranges::dangling](http://en.cppreference.com/w/cpp/ranges-dangling-placeholder/dangling), decltype(dangling_iter)>);
    //  *dangling_iter; // compilation error (i.e. dangling protection works.)
     
        auto my = MyRange<int, 4>{{1, 2, 42, 3}};
        auto valid_iter = std::[ranges::max_element](http://en.cppreference.com/w/cpp/algorithm/ranges/max_element)(my);
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << *valid_iter << ' '; // OK: 42
     
        auto getMyBorrowedRangeByValue = []
        {
            static int sa[4]{1, 2, 42, 3};
            return MyBorrowedRange<int, [std::size](http://en.cppreference.com/w/cpp/iterator/size)(sa)>{sa};
        };
        auto valid_iter2 = std::[ranges::max_element](http://en.cppreference.com/w/cpp/algorithm/ranges/max_element)(getMyBorrowedRangeByValue());
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << *valid_iter2 << '\n'; // OK: 42
    }

Output:

    
    
    42 42

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

[ ranges::dangling  ](/w/cpp/ranges/dangling "cpp/ranges/dangling") (C++20)  |  a placeholder type indicating that an iterator or a ` subrange ` should not be returned since it would be dangling   
(class)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_dangling&action=edit)  
---|---  
  
Retrieved from " [
https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/borrowed_range&oldid=170162
](https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/borrowed_range&oldid=170162)
"

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

  * In other languages 

  * [ Español ](http://es.cppreference.com/w/cpp/ranges/borrowed_range "cpp/ranges/borrowed range")
  * [ 日本語 ](http://ja.cppreference.com/w/cpp/ranges/b