|
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 |
|
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 |
|
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 |
|
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>
int main()
{
std::vector<int> numbers{1, 2, 3, 4};
auto even = numbers
return num % 2 == 0;
});
std::cout << even << '\n';
}
Output
Syntax
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