ranges::views::filter_fn Struct Reference

`#include <range/v3/view/filter.hpp>`

Inheritance diagram for ranges::views::filter_fn:

## Public Member Functions

template<typename Pred , typename Proj >
CPP_TEMPLATE_AUX_0 | c (requires(!range< Pred >)) ccconstexpr auto operator()(Pred pred
template<typename Pred >
constexpr auto | operator() (Pred pred) const
Public Member Functions inherited from ranges::views::filter_base_fn
template<typename Rng , typename Pred , typename Proj >
CPP_TEMPLATE_AUX_0 | c (requires viewable_range< Rng > &&input_range< Rng > &&indirect_unary_predicate< Pred, projected< iterator_t< Rng >, Proj >>) ccconstexpr filter_view< all_t< Rng >
CPP_TEMPLATE_AUX_0 composed< Pred, Proj > | operator() (Rng &&rng, Pred pred, Proj proj) const
Public Member Functions inherited from ranges::views::cpp20_filter_base_fn
template<typename Rng , typename Pred >
CPP_TEMPLATE_AUX_0 | c (requires viewable_range< Rng > &&input_range< Rng > &&indirect_unary_predicate< Pred, iterator_t< Rng >>) ccconstexpr filter_view< all_t< Rng >
CPP_TEMPLATE_AUX_0 Pred | operator() (Rng &&rng, Pred pred) const

## Public Attributes

CPP_TEMPLATE_AUX_0 Proj proj | const

## Related Functions

(Note that these are not member functions.)
constexpr filter_fn | filter {}

## Detailed Description

# ranges::views::filter

The filter view takes in a predicate function `T -> bool` and converts an input range of `T` into an output range of `T` by keeping all elements for which the predicate returns true.

## Example

#include <iostream>
#include <vector>
#include <range/v3/view/filter.hpp>
int main()
{
std::vector<int> numbers{1, 2, 3, 4};
auto even = numbers
// Keep only the even numbers
| ranges::views::filter([](const int& num) {
return num % 2 == 0;
});
std::cout << even << '\n';
}
filter.hpp
meta::filter
join< transform< L, detail::filter_< Pred > >> filter
Returns a new meta::list where only those elements of L that satisfy the Callable Pred such that invo...
Definition: meta.hpp:2818

### Output

[2,4]

## Syntax

auto output_range = input_range | ranges::views::filter(filter_func);

## Parameters

    filter_func

- Called once for each element of the input range
- Returns true for elements that should present in the output range

    input_range

- The range of elements to filter
- Reference type: `T`

    output_range

- The range of filtered values
  - Is either a `forward_range` or the concept satisfied by the input
  - Is a `common_range` if the input is a `common_range`
  - Is not a `sized_range` or `borrowed_range`
- Reference type: `T`

## Member Data Documentation

## const

CPP_TEMPLATE_AUX_0 Proj proj ranges::views::filter_fn::const

Initial value:
{
return make_view_closure(
bind_back(filter_base_fn{}, std::move(pred), std::move(proj)))
ranges::aux::move
constexpr move_fn move
Definition: move.hpp:52
ranges::make_view_closure
constexpr make_view_closure_fn make_view_closure
Definition: view.hpp:103
meta::lazy::bind_back
defer< bind_back, Fn, Ts... > bind_back
Definition: meta.hpp:994