GrPPI  0.3.1
Generic and Reusable Parallel Pattern Interface
farm_pattern.h
Go to the documentation of this file.
1 
20 #ifndef GRPPI_COMMON_FARM_PATTERN_H
21 #define GRPPI_COMMON_FARM_PATTERN_H
22 
23 #include <type_traits>
24 
25 namespace grppi {
26 
32 template <typename Transformer>
33 class farm_t {
34 public:
35 
36  using transformer_type = Transformer;
37 
43  farm_t(int n, Transformer && t) noexcept :
44  cardinality_{n}, transformer_{t}
45  {}
46 
51  int cardinality() const noexcept {
52  return cardinality_;
53  }
54 
59  Transformer & transformer(){
60  return transformer_;
61  }
65  template <typename I>
66  auto operator()(I && item) const {
67  return transformer_(std::forward<I>(item));
68  }
69 
70 private:
71  int cardinality_;
72  Transformer transformer_;
73 };
74 
75 namespace internal {
76 
77 template<typename T>
78 struct is_farm : std::false_type {};
79 
80 template<typename T>
81 struct is_farm<farm_t<T>> : std::true_type {};
82 
83 } // namespace internal
84 
85 template <typename T>
86 static constexpr bool is_farm = internal::is_farm<std::decay_t<T>>();
87 
88 template <typename T>
89 using requires_farm = typename std::enable_if_t<is_farm<T>, int>;
90 
91 }
92 
93 #endif
static constexpr bool is_farm
Definition: farm_pattern.h:86
Definition: callable_traits.h:26
auto operator()(I &&item) const
Invokes the trasnformer of the farm over a data item.
Definition: farm_pattern.h:66
Definition: farm_pattern.h:78
int cardinality() const noexcept
Farm&#39;s cardinality or number of replicas.
Definition: farm_pattern.h:51
Representation of farm pattern. Represents a farm of n replicas from a transformer.
Definition: farm_pattern.h:33
Transformer transformer_type
Definition: farm_pattern.h:36
farm_t(int n, Transformer &&t) noexcept
Constructs a farm with a cardinality and a transformer.
Definition: farm_pattern.h:43
typename std::enable_if_t< is_farm< T >, int > requires_farm
Definition: farm_pattern.h:89
Transformer & transformer()
Return the transformer function stored in the farm pattern.
Definition: farm_pattern.h:59