or to the end. Equivalent to

    
    
    if constexpr ([ranges::common_range](http://en.cppreference.com/w/cpp/ranges/common_range)<V>)
        return /* iterator */{*this, [ranges::end](http://en.cppreference.com/w/cpp/ranges-ranges-placeholder/end)(base_)};
    else
        return /* sentinel */{*this};

###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/filter_view&action=edit&section=4 "Edit
section: Deduction guides") ]  Deduction guides

template  < class  R,  class  Pred  >  
filter_view  (  R  && , Pred  )  \-  > filter_view  < [ views::  all_t  ](http://en.cppreference.com/w/cpp/ranges/all_view) < R  > , Pred  > ;  |  |  (since C++20)   
---|---|---  
|  |   
  
###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/filter_view&action=edit&section=5 "Edit
section: Nested classes") ]  Nested classes

[ _ iterator  _ ](/w/cpp/ranges/filter_view/iterator "cpp/ranges/filter view/iterator") (C++20)  |  the iterator type of ` filter_view `   
(  exposition-only member class*  )  
---|---  
[ _ sentinel  _ ](/w/cpp/ranges/filter_view/sentinel "cpp/ranges/filter view/sentinel") (C++20)  |  the sentinel type of ` filter_view ` when the underlying view is not a [ ` common_range ` ](/w/cpp/ranges/common_range "cpp/ranges/common range")   
(  exposition-only member class*  )  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/filter_view&action=edit&section=6 "Edit
section: Example") ]  Example

Run this code

    
    
    #include <iostream>
    #include <ranges>
     
    int main()
    {
        auto even = [](int i) { return 0 == i % 2; };
        auto square = [](int i) { return i * i; };
     
        for (int i : std::[views::iota](http://en.cppreference.com/w/cpp/ranges/iota_view)(0, 6)
                   | std::views::filter(even)
                   | std::[views::transform](http://en.cppreference.com/w/cpp/ranges/transform_view)(square))
            [std::cout](http://en.cppreference.com/w/cpp/io/cout) << i << ' ';
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '\n';
    }

Output:

    
    
    0 4 16

###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/filter_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 3714 ](https://cplusplus.github.io/LWG/issue3714)  
( [ P2711R1 ](https://wg21.link/P2711R1) )  |  C++20  |  the multi-parameter constructor was not explicit  |  made explicit   
[ P2325R3 ](https://wg21.link/P2325R3) |  C++20  |  if ` Pred ` is not [ ` default_initializable ` ](/w/cpp/concepts/default_initializable "cpp/concepts/default initializable") , the default constructor   
constructs a ` filter_view ` which does not contain a ` Pred ` |  the ` filter_view ` is also   
not [ ` default_initializable ` ](/w/cpp/concepts/default_initializable
"cpp/concepts/default initializable")  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/filter_view&action=edit&section=8 "Edit
section: See also") ]  See also

[ 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)  
---|---  
  
Retrieved from " [
https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/filter_view&oldid=160901
](https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/filter_view&oldid=160901)
"

#####  Navigation

  * [ Support us ](http://www.cppreference.com/support)
  * [ Recent changes ](/w/Special:RecentChanges "A list of recent changes in the wiki \[r\]")