GrPPI  0.3.1
Generic and Reusable Parallel Pattern Interface
common/context.h
Go to the documentation of this file.
1 
20 #ifndef GRPPI_COMMON_CONTEXT_H
21 #define GRPPI_COMMON_CONTEXT_H
22 
23 #include <type_traits>
24 
25 namespace grppi {
26 
35 template <typename ExecutionPolicy, typename Transformer>
36 class context_t {
37 public:
38 
39  using transformer_type = Transformer;
40  using execution_policy_type = ExecutionPolicy;
41 
47  context_t(ExecutionPolicy & e, Transformer && t) noexcept :
48  execution_policy_{e}, transformer_{t}
49  {}
50 
55  ExecutionPolicy & execution_policy(){
56  return execution_policy_;
57  }
58 
59 
64  Transformer & transformer(){
65  return transformer_;
66  }
67 
71  template <typename I>
72  auto operator()(I && item) const {
73  return transformer_(std::forward<I>(item));
74  }
75 
76 private:
77  Transformer transformer_;
78  ExecutionPolicy& execution_policy_;
79 };
80 
81 namespace internal {
82 
83 template<typename T>
84 struct is_context : std::false_type {};
85 
86 template<typename E, typename T>
87 struct is_context<context_t<E,T>> : std::true_type {};
88 
89 } // namespace internal
90 
91 template <typename T>
93 
94 template <typename T>
95 using requires_context = typename std::enable_if_t<is_context<T>, int>;
96 
97 }
98 
99 #endif
Transformer & transformer()
Return the transformer function.
Definition: common/context.h:64
Definition: callable_traits.h:26
Representation of a context pattern. Represents a context that uses a given policy to run a transform...
Definition: common/context.h:36
Transformer transformer_type
Definition: common/context.h:39
ExecutionPolicy execution_policy_type
Definition: common/context.h:40
context_t(ExecutionPolicy &e, Transformer &&t) noexcept
Constructs a context with a execution policy and a transformer.
Definition: common/context.h:47
Definition: common/context.h:84
auto operator()(I &&item) const
Invokes the trasnformer of the context over a data item.
Definition: common/context.h:72
ExecutionPolicy & execution_policy()
Return the execution policy used in the context.
Definition: common/context.h:55
typename std::enable_if_t< is_context< T >, int > requires_context
Definition: common/context.h:95
static constexpr bool is_context
Definition: common/context.h:92