GrPPI  0.2
Generic and Reusable Parallel Pattern Interface
poly/stream_filter.h
Go to the documentation of this file.
1 
21 #ifndef GRPPI_POLY_STREAM_FILTER_H
22 #define GRPPI_POLY_STREAM_FILTER_H
23 
24 #include "polymorphic_execution.h"
25 #include "../common/support.h"
26 
27 namespace grppi {
28 
29 template <typename Generator, typename Predicate, typename Consumer>
30 void keep_multi_impl(polymorphic_execution, Generator && generate_op,
31  Predicate predicate_op, Consumer consume_op)
32 {
33 }
34 
35 template <typename E, typename ... O,
36  typename Generator, typename Predicate, typename Consumer,
39  Generator && generate_op,
40  Predicate && predicate_op, Consumer && consume_op)
41 {
42  keep_multi_impl<O...>(ex, std::forward<Generator>(generate_op),
43  std::forward<Predicate>(predicate_op), std::forward<Consumer>(consume_op));
44 }
45 
46 
47 
48 template <typename E, typename ... O,
49  typename Generator, typename Predicate, typename Consumer,
52  Generator && generate_op,
53  Predicate && predicate_op,
54  Consumer && consume_op)
55 {
56  if (typeid(E) == ex.type()) {
57  keep(*ex.execution_ptr<E>(),
58  std::forward<Generator>(generate_op), std::forward<Predicate>(predicate_op),
59  std::forward<Consumer>(consume_op));
60  }
61  else {
62  keep_multi_impl<O...>(ex, std::forward<Generator>(generate_op),
63  std::forward<Predicate>(predicate_op), std::forward<Consumer>(consume_op));
64  }
65 }
66 
67 
68 template <typename Generator, typename Predicate, typename Consumer>
69 void discard_multi_impl(polymorphic_execution, Generator && generate_op,
70  Predicate predicate_op, Consumer consume_op)
71 {
72 }
73 
74 template <typename E, typename ... O,
75  typename Generator, typename Predicate, typename Consumer,
76  internal::requires_execution_not_supported<E> = 0>
78  Generator && generate_op,
79  Predicate && predicate_op, Consumer && consume_op)
80 {
81  discard_multi_impl<O...>(ex, std::forward<Generator>(generate_op),
82  std::forward<Predicate>(predicate_op), std::forward<Consumer>(consume_op));
83 }
84 
85 
86 
87 template <typename E, typename ... O,
88  typename Generator, typename Predicate, typename Consumer,
89  internal::requires_execution_supported<E> = 0>
91  Generator && generate_op,
92  Predicate && predicate_op,
93  Consumer && consume_op)
94 {
95  if (typeid(E) == ex.type()) {
96  discard(*ex.execution_ptr<E>(),
97  std::forward<Generator>(generate_op), std::forward<Predicate>(predicate_op),
98  std::forward<Consumer>(consume_op));
99  }
100  else {
101  discard_multi_impl<O...>(ex, std::forward<Generator>(generate_op),
102  std::forward<Predicate>(predicate_op), std::forward<Consumer>(consume_op));
103  }
104 }
105 
127 template <typename Generator, typename Predicate, typename Consumer>
128 void keep(polymorphic_execution & ex, Generator && generate_op,
129  Predicate && predicate_op, Consumer && consume_op)
130 {
136  >(ex, std::forward<Generator>(generate_op),
137  std::forward<Predicate>(predicate_op),
138  std::forward<Consumer>(consume_op));
139 }
140 
154 template <typename Generator, typename Predicate, typename Consumer>
155 void discard(polymorphic_execution & ex, Generator && generate_op,
156  Predicate && predicate_op, Consumer && consume_op)
157 {
163  >(ex, std::forward<Generator>(generate_op),
164  std::forward<Predicate>(predicate_op),
165  std::forward<Consumer>(consume_op));
166 }
173 } // end namespace grppi
174 
175 #endif
Definition: callable_traits.h:24
void discard_multi_impl(polymorphic_execution, Generator &&generate_op, Predicate predicate_op, Consumer consume_op)
Definition: poly/stream_filter.h:69
Native parallel execution policy. This policy uses ISO C++ threads as implementation building block a...
Definition: parallel_execution_native.h:136
const std::type_info & type() const noexcept
Definition: polymorphic_execution.h:77
std::enable_if_t< is_supported< E >(), int > requires_execution_supported
Definition: support.h:32
OpenMP parallel execution policy.
Definition: parallel_execution_omp.h:40
TBB parallel execution policy.
Definition: parallel_execution_tbb.h:37
void discard(parallel_execution_native &ex, Generator generate_op, Predicate predicate_op, Consumer consume_op)
Invoke Filter pattern on a data sequence with sequential execution policy. This function discards fro...
Definition: native/stream_filter.h:177
void keep(parallel_execution_native &ex, Generator generate_op, Predicate predicate_op, Consumer consume_op)
Invoke Filter pattern pattern on a data sequence with sequential execution policy. This function keeps in the stream only those items that satisfy the predicate.
Definition: native/stream_filter.h:50
E * execution_ptr()
Get the execution pointer for a given type.
Definition: polymorphic_execution.h:91
Sequential execution policy.
Definition: sequential_execution.h:31
Definition: polymorphic_execution.h:63
std::enable_if_t<!is_supported< E >(), int > requires_execution_not_supported
Definition: support.h:36
void keep_multi_impl(polymorphic_execution, Generator &&generate_op, Predicate predicate_op, Consumer consume_op)
Definition: poly/stream_filter.h:30