ember function of ` std::ranges::view_interface<D> ` )  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/view_interface/dsc_operator_at&action=edit)  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/take_view&action=edit&section=2 "Edit
section: Deduction guides") ]  [ Deduction guides
](/w/cpp/ranges/take_view/deduction_guides "cpp/ranges/take view/deduction
guides")

###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/take_view&action=edit&section=3 "Edit
section: Nested classes") ]  Nested classes

[ _ sentinel  _ ](/w/cpp/ranges/take_view/sentinel "cpp/ranges/take view/sentinel") (C++20)  |  the sentinel type   
(  exposition-only member class template*  )  
---|---  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/take_view&action=edit&section=4 "Edit
section: Helper templates") ]  Helper templates

template  < class  T  >  
inline  constexpr  bool  enable_borrowed_range  < std  ::  ranges  ::
take_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 ` take_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/take_view&action=edit&section=5 "Edit
section: Example") ]  Example

Run this code

    
    
    #include <algorithm>
    #include <iostream>
    #include <ranges>
     
    auto print = [](char x){ [std::cout](http://en.cppreference.com/w/cpp/io/cout) << x; };
     
    int main()
    {
        constexpr char pi[]{'3', '.', '1', '4', '1', '5', '9', '2'};
     
        std::[ranges::for_each](http://en.cppreference.com/w/cpp/algorithm/ranges/for_each)(pi | std::ranges::views::take(6), print);
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '\n';
     
        // safely takes 8 chars only, i.e. min(pi.size(), 42)
        std::[ranges::for_each](http://en.cppreference.com/w/cpp/algorithm/ranges/for_each)(std::ranges::take_view{pi, 42}, print);
     
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '\n';
    }

Output:

    
    
    3.1415
    3.141592

###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/take_view&action=edit&section=6 "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 3407 ](https://cplusplus.github.io/LWG/issue3407) |  C++20  |  ` views::take ` sometimes failed to   
construct a sized random access range  |  the result type is adjusted so   
that construction is always valid  
[ LWG 3494 ](https://cplusplus.github.io/LWG/issue3494) |  C++20  |  ` take_view ` was never a ` borrowed_range ` |  it is a ` borrowed_range ` if its underlying view is   
  
###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/take_view&action=edit&section=7 "Edit
section: See also") ]  See also

[ views::counted  ](/w/cpp/ranges/view_counted "cpp/ranges/view counted") (C++20)  |  creates a subrange from an iterator and a count   
(customization point object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_view_counted&action=edit)  
---|---  
[ ranges::take_while_view  views::take_while  ](/w/cpp/ranges/take_while_view "cpp/ranges/take while view") (C++20)  |  a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") consisting of the initial elements of another [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") , until the first element on which a predicate returns  false    
(class template)  (range adaptor object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_take_while_view&action=edit)  
[ ranges::