GrPPI  0.3.1
Generic and Reusable Parallel Pattern Interface
filter_pattern.h
Go to the documentation of this file.
1 
20 #ifndef GRPPI_COMMON_FILTER_PATTERN_H
21 #define GRPPI_COMMON_FILTER_PATTERN_H
22 
23 #include <type_traits>
24 
25 namespace grppi {
26 
32 template <typename Predicate>
33 class filter_t {
34 public:
35 
40  filter_t(Predicate && p) noexcept :
41  predicate_{p}
42  {}
43 
47  template <typename I>
48  bool operator()(I && item) const {
49  return predicate_(std::forward<I>(item));
50  }
51 
52 private:
53  Predicate predicate_;
54 };
55 
56 namespace internal {
57 
58 template<typename T>
59 struct is_filter : std::false_type {};
60 
61 template<typename T>
62 struct is_filter<filter_t<T>> : std::true_type {};
63 
64 } // namespace internal
65 
66 template <typename T>
68 
69 template <typename T>
70 using requires_filter = typename std::enable_if_t<is_filter<T>, int>;
71 
72 }
73 
74 #endif
static constexpr bool is_filter
Definition: filter_pattern.h:67
Definition: callable_traits.h:26
filter_t(Predicate &&p) noexcept
Constructs a filter with a predicate.
Definition: filter_pattern.h:40
typename std::enable_if_t< is_filter< T >, int > requires_filter
Definition: filter_pattern.h:70
bool operator()(I &&item) const
Invokes the predicate of the filter over a data item.
Definition: filter_pattern.h:48
Representation of filter pattern. Represents a filter that can be used as a stage on a pipeline...
Definition: filter_pattern.h:33
Definition: filter_pattern.h:59