16 #ifndef GRPPI_COMMON_PIPELINE_PATTERN_H
17 #define GRPPI_COMMON_PIPELINE_PATTERN_H
19 #include <type_traits>
29 template <
typename ... Transformers>
41 transformers_{others...}
46 template <std::size_t index,
typename T,
typename std::enable_if< index == (
sizeof...(Transformers) -1) ,
int>::type = 0 >
49 return invoke<index>(item);
52 template <std::size_t index,
typename T,
typename std::enable_if< index != (
sizeof...(Transformers) -1) ,
int>::type = 0 >
55 return invoke_all<index+1>(invoke<index>(item));
60 return invoke_all<0>(item);
67 template <std::
size_t I,
typename T>
69 auto f = std::get<I>(transformers_);
70 return f(std::forward<T>(item));
78 template <std::
size_t I>
80 static_assert(I<
sizeof...(Transformers),
81 "Pipeline has not so many transformers");
82 return std::get<I>(transformers_);
90 std::tuple<Transformers...> transformers_;
98 template <
typename ... T>
103 template <
typename T>
106 template <
typename T>
111 template <
typename I,
typename T>
113 using type = std::decay_t<
typename std::result_of<T(I)>
::type>;
116 template <
typename I,
typename T,
typename ... U>
119 using type = std::conditional_t<
sizeof...(U)==0,
127 template <
typename I,
typename T>
Representation of pipeline pattern. Represents a pipeline with multiple chained transformers.
Definition: pipeline_pattern.h:30
auto invoke(T &&item) const
Invokes a trasnformer from the pipeline.
Definition: pipeline_pattern.h:68
auto invoke_all(T item) const
Definition: pipeline_pattern.h:47
auto transformers() const noexcept
Definition: pipeline_pattern.h:85
auto stage() const noexcept
Gets a transformer from the pipeline.
Definition: pipeline_pattern.h:79
auto operator()(T item) const
Definition: pipeline_pattern.h:59
pipeline_t(Transformers &&... others) noexcept
Constructs a pipeline with several transformers.
Definition: pipeline_pattern.h:40
std::tuple< Transformers... > transformers_type
Definition: pipeline_pattern.h:33
Definition: callable_traits.h:21
typename std::enable_if_t< is_pipeline< T >, int > requires_pipeline
Definition: pipeline_pattern.h:107
typename internal::output_value_type< I, T >::type output_value_type
Definition: pipeline_pattern.h:128
static constexpr bool is_pipeline
Definition: pipeline_pattern.h:104
Definition: pipeline_pattern.h:96
std::decay_t< typename std::result_of< T(I)>::type > first_result
Definition: pipeline_pattern.h:118
std::conditional_t< sizeof...(U)==0, first_result, typename output_value_type< first_result, U... >::type > type
Definition: pipeline_pattern.h:122
Definition: pipeline_pattern.h:112
std::decay_t< typename std::result_of< T(I)>::type > type
Definition: pipeline_pattern.h:113