GrPPI  0.2
Generic and Reusable Parallel Pattern Interface
seq/stream_filter.h
Go to the documentation of this file.
1 
21 #ifndef GRPPI_SEQ_STREAM_FILTER_H
22 #define GRPPI_SEQ_STREAM_FILTER_H
23 
24 #include "sequential_execution.h"
25 
26 namespace grppi {
27 
49 template <typename Generator, typename Predicate, typename Consumer>
50 void keep(sequential_execution, Generator generate_op,
51  Predicate predicate_op, Consumer consume_op)
52 {
53  for (;;) {
54  auto item = generate_op();
55  if (!item) break;
56  if (predicate_op(*item)) {
57  consume_op(*item);
58  }
59  }
60 }
61 
75 template <typename Generator, typename Predicate, typename Consumer>
76 void discard(sequential_execution & ex, Generator generate_op,
77  Predicate predicate_op, Consumer consume_op)
78 {
79  keep(ex,
80  std::forward<Generator>(generate_op),
81  [&](auto val) { return !predicate_op(val); },
82  std::forward<Consumer>(consume_op)
83  );
84 }
85 
91 }
92 
93 #endif
Definition: callable_traits.h:24
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
Sequential execution policy.
Definition: sequential_execution.h:31