nge  < ranges  ::  ref_view  < T  >> =  true  ;  |  |  (since C++20)   
---|---|---  
|  |   
  
This specialization of [ ` std::ranges::enable_borrowed_range `
](/w/cpp/ranges/borrowed_range "cpp/ranges/borrowed range") makes  ` ref_view
` satisfy [ ` borrowed_range ` ](/w/cpp/ranges/borrowed_range
"cpp/ranges/borrowed range") .

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

Run this code

    
    
    #include <iostream>
    #include <ranges>
     
    int main()
    {
        const [std::string](http://en.cppreference.com/w/cpp/string/basic_string) s{"cosmos"};
     
        const std::[ranges::take_view](http://en.cppreference.com/w/cpp/ranges/take_view) tv{s, 3};
        const std::ranges::ref_view rv{tv};
     
        [std::cout](http://en.cppreference.com/w/cpp/io/cout)
            << [std::boolalpha](http://en.cppreference.com/w/cpp/io/manip/boolalpha)
            << "call empty() : " << rv.empty() << '\n'
            << "call size()  : " << rv.size() << '\n'
            << "call begin() : " << *rv.begin() << '\n'
            << "call end()   : " << *(rv.end() - 1) << '\n'
            << "call data()  : " << rv.data() << '\n'
            << "call base()  : " << rv.base().size() << '\n' // ~> tv.size()
            << "range-for    : ";
     
        for (const auto c : rv)
            [std::cout](http://en.cppreference.com/w/cpp/io/cout) << c;
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '\n';
    }

Output:

    
    
    call empty() : false
    call size()  : 3
    call begin() : c
    call end()   : s
    call data()  : cosmos
    call base()  : 3
    range-for    : cos

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

The following behavior-changing defect reports were applied retroactively to
previously published C++ standards.

DR  |  Applied to  |  Behavior as published  |  Correct behavior   
---|---|---|---  
[ P2325R3 ](https://wg21.link/P2325R3) |  C++20  |  default constructor was provided as [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view")   
must be [ ` default_initializable ` ](/w/cpp/concepts/default_initializable "cpp/concepts/default initializable") |  removed along with the requirement   
  
###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/ref_view&action=edit&section=8 "Edit
section: See also") ]  See also

[ reference_wrapper  ](/w/cpp/utility/functional/reference_wrapper "cpp/utility/functional/reference wrapper") (C++11)  |  [ CopyConstructible  ](/w/cpp/named_req/CopyConstructible "cpp/named req/CopyConstructible") and [ CopyAssignable  ](/w/cpp/named_req/CopyAssignable "cpp/named req/CopyAssignable") reference wrapper   
(class template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/utility/functional/dsc_reference_wrapper&action=edit)  
---|---  
[ ranges::owning_view  ](/w/cpp/ranges/owning_view "cpp/ranges/owning view") (C++20)  |  a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") with unique ownership of some [ ` range ` ](/w/cpp/ranges/range "cpp/ranges/range")   
(class template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_owning_view&action=edit)  
[ views::all_t  views::all  ](/w/cpp/ranges/all_view "cpp/ranges/all view") (C++20)  |  a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") that includes all elements of a [ ` range ` ](/w/cpp/ranges/range "cpp/ranges/range")   
(alias template)  (range adaptor object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_all_view&action=edit)  
  
Retrieved from " [
https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/ref_view&oldid=160904
](https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/ref_view&oldid=160904)
"

#####  Navigation

  * [ Support us ](http://www.cppreference.com/support)
  * [ Recent changes ](/w/Special:RecentChanges "A li