_view&action=edit&section=2
"Edit section: Deduction guides") ]  [ Deduction guides
](/w/cpp/ranges/take_while_view/deduction_guides "cpp/ranges/take while
view/deduction guides")

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

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

Run this code

    
    
    #include <iostream>
    #include <ranges>
     
    int main()
    {
        for (int year : std::[views::iota](http://en.cppreference.com/w/cpp/ranges/iota_view)(2020)
                      | std::views::take_while([](int y) { return y <= 2023; }))
            [std::cout](http://en.cppreference.com/w/cpp/io/cout) << year << ' ';
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '\n';
     
        const char idea[] {"Today is yesterday's tomorrow!..."};
        for (char x : std::ranges::take_while_view(idea, [](char c) { return c != '.'; }))
            [std::cout](http://en.cppreference.com/w/cpp/io/cout) << x;
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '\n';
    }

Output:

    
    
    2020 2021 2022 2023
    Today is yesterday's tomorrow!

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

[ ranges::take_view  views::take  ](/w/cpp/ranges/take_view "cpp/ranges/take view") (C++20)  |  a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") consisting of the first N elements of another [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view")   
(class template)  (range adaptor object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_take_view&action=edit)  
---|---  
[ ranges::drop_while_view  views::drop_while  ](/w/cpp/ranges/drop_while_view "cpp/ranges/drop while view") (C++20)  |  a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") consisting of the elements of another [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") , skipping the initial subsequence of elements until the first element where the predicate returns  false    
(class template)  (range adaptor object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_drop_while_view&action=edit)  
  
Retrieved from " [
https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/take_while_view&oldid=160939
](https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/take_while_view&oldid=160939)
"

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

  * In other languages 

  * [ Español ](http://es.cppreference.com/w/cpp/ranges/take_while_view "cpp/ranges/take while view")
  * [ 日本語 ](http://ja.cppreference.com/w/cpp/ranges/take_while_view "cpp/ranges/take while vi