Range-v3
Range algorithms, views, and actions for the Standard Library
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 >
constexpr auto operator() (Pred pred) const
 
template<typename Pred , typename Proj >
requires (!range<Pred>)
constexpr auto operator() (Pred pred, Proj proj) const
 
- Public Member Functions inherited from ranges::views::filter_base_fn
template<typename Rng , typename Pred , typename Proj >
requires viewable_range<Rng> && input_range<Rng> && indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>
constexpr filter_view< all_t< Rng >, 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 >
requires viewable_range<Rng> && input_range<Rng> && indirect_unary_predicate<Pred, iterator_t<Rng>>
constexpr filter_view< all_t< Rng >, Pred > operator() (Rng &&rng, Pred pred) 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>
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';
}
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

The input_range concept.
Definition: concepts.hpp:97
The output_range concept.
Definition: concepts.hpp:88

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