e  < class  T  >  
inline  constexpr  bool  enable_borrowed_range  < std  ::  ranges  ::
common_view  < T  >> =  
std  ::  [ ranges::  enable_borrowed_range  ](http://en.cppreference.com/w/cpp/ranges/borrowed_range) < T  > ;  |  |  (since C++20)   
---|---|---  
|  |   
  
This specialization of [ ` std::ranges::enable_borrowed_range `
](/w/cpp/ranges/borrowed_range "cpp/ranges/borrowed range") makes `
common_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/common_view&action=edit&section=5 "Edit
section: Notes") ]  Notes

` common_view ` can be useful for working with legacy algorithms that expect
the iterator and sentinel are of the same type.

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

Run this code

    
    
    #include <iostream>
    #include <iterator>
    #include <list>
    #include <numeric>
    #include <ranges>
     
    int main()
    {
        auto v1 = {1, 2, 3, 4, 5};
        auto i1 = [std::counted_iterator](http://en.cppreference.com/w/cpp/iterator/counted_iterator){v1.begin(), [std::ssize](http://en.cppreference.com/w/cpp/iterator/size)(v1)};
        auto r1 = std::[ranges::subrange](http://en.cppreference.com/w/cpp/ranges/subrange){i1, [std::default_sentinel](http://en.cppreference.com/w/cpp/iterator/default_sentinel_t)};
    //  auto e1 = std::accumulate(r1.begin(), r1.end(), 0); // error: "common range" required
        auto c1 = std::ranges::common_view{r1};
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "accumulate: " << [std::accumulate](http://en.cppreference.com/w/cpp/algorithm/accumulate)(c1.begin(), c1.end(), 0) << '\n';
     
        // inherited from ranges::view_interface:
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "c1.front(): " << c1.front() << '\n';
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "c1.back(): " << c1.back() << '\n';
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "c1.data(): " << c1.data() << '\n';
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "c1[0]: " << c1[0] << '\n';
     
        auto v2 = [std::list](http://en.cppreference.com/w/cpp/container/list){1, 2, 3, 4, 5};
        auto i2 = [std::counted_iterator](http://en.cppreference.com/w/cpp/iterator/counted_iterator){v2.begin(), [std::ssize](http://en.cppreference.com/w/cpp/iterator/size)(v2)};
        auto r2 = std::[ranges::subrange](http://en.cppreference.com/w/cpp/ranges/subrange){i2, [std::default_sentinel](http://en.cppreference.com/w/cpp/iterator/default_sentinel_t)};
    //  auto e2 = std::accumulate(r2.begin(), r2.end(), 0); // error: "common range" required
        auto c2 = std::ranges::common_view{ r2 };
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "accumulate: " << [std::accumulate](http://en.cppreference.com/w/cpp/algorithm/accumulate)(c2.begin(), c2.end(), 0) << '\n';
     
        // inherited from ranges::view_interface:
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "c2.front(): " << c2.front() << '\n';
    //  auto e3 = c2.back(); // error: "bidirectional range" required
    //  auto e4 = c2.data(); // error: "contiguous range" required
    //  auto e5 = c2[0];     // error: "random access range" required
    }

Possible output:

    
    
    accumulate: 15
    c1.front(): 1
    c1.back(): 5
    c1.data(): 0x7f19937f00d0
    c1[0]: 1
    accumulate: 15
    c2.front(): 1

###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/common_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   
---|---|---|---  
[ LWG 3494 ](https://cplusplus.github.io/LWG/issue3494) |  C++20