GrPPI  0.3.1
Generic and Reusable Parallel Pattern Interface
iteration_pattern.h
Go to the documentation of this file.
1 
20 #ifndef GRPPI_COMMON_ITERATION_PATTERN_H
21 #define GRPPI_COMMON_ITERATION_PATTERN_H
22 
23 #include <type_traits>
24 
25 namespace grppi {
26 
32 template <typename Transformer, typename Predicate>
33 class iteration_t {
34 public:
35 
40  iteration_t(Transformer && t, Predicate && p) noexcept :
41  transform_{t},
42  predicate_{p}
43  {}
44 
48  template <typename Item>
49  bool predicate(Item && item) const {
50  return predicate_(std::forward<Item>(item));
51  }
52 
56  template <typename Item>
57  auto transform(Item && item) const {
58  return transform_(std::forward<Item>(item));
59  }
60 
64  template<typename T>
65  auto operator()(T && item){
66  return transform(item);
67  }
68 
69 private:
70  Transformer transform_;
71  Predicate predicate_;
72 };
73 
74 namespace internal {
75 
76 template<typename T>
77 struct is_iteration : std::false_type {};
78 
79 template<typename T, typename P>
80 struct is_iteration<iteration_t<T,P>> : std::true_type {};
81 
82 } // namespace internal
83 
84 template <typename T>
86 
87 template <typename T>
88 using requires_iteration = typename std::enable_if_t<is_iteration<T>, int>;
89 
90 }
91 
92 #endif
Definition: callable_traits.h:26
iteration_t(Transformer &&t, Predicate &&p) noexcept
Constructs a iteration with a predicate.
Definition: iteration_pattern.h:40
auto transform(Item &&item) const
Applies the transformation over a data item.
Definition: iteration_pattern.h:57
typename std::enable_if_t< is_iteration< T >, int > requires_iteration
Definition: iteration_pattern.h:88
auto operator()(T &&item)
Applies the transformation over a data item.
Definition: iteration_pattern.h:65
static constexpr bool is_iteration
Definition: iteration_pattern.h:85
Definition: iteration_pattern.h:77
bool predicate(Item &&item) const
Invokes the predicate of the iteration over a data item.
Definition: iteration_pattern.h:49
Representation of iteration pattern. Represents a iteration that can be used as a stage on a pipeline...
Definition: iteration_pattern.h:33