20 #ifndef GRPPI_COMMON_PIPELINE_PATTERN_H 21 #define GRPPI_COMMON_PIPELINE_PATTERN_H 23 #include <type_traits> 33 template <
typename ... Transformers>
45 transformers_{others...}
50 template <std::size_t index,
typename T,
typename std::enable_if< index == (
sizeof...(Transformers) -1) ,
int>::type = 0 >
53 return invoke<index>(item);
56 template <std::size_t index,
typename T,
typename std::enable_if< index != (
sizeof...(Transformers) -1) ,
int>::type = 0 >
59 return invoke_all<index+1>(invoke<index>(item));
64 return invoke_all<0>(item);
71 template <std::
size_t I,
typename T>
73 auto f = std::get<I>(transformers_);
74 return f(std::forward<T>(item));
82 template <std::
size_t I>
84 static_assert(I<
sizeof...(Transformers),
85 "Pipeline has not so many transformers");
86 return std::get<I>(transformers_);
94 std::tuple<Transformers...> transformers_;
102 template <
typename ... T>
107 template <
typename T>
110 template <
typename T>
115 template <
typename I,
typename T>
117 using type = std::decay_t<typename std::result_of<T(I)>::type>;
120 template <
typename I,
typename T,
typename ... U>
122 using first_result = std::decay_t<typename std::result_of<T(I)>::type>;
123 using type = std::conditional_t<
sizeof...(U)==0,
131 template <
typename I,
typename T>
Definition: callable_traits.h:26
auto invoke(T &&item) const
Invokes a trasnformer from the pipeline.
Definition: pipeline_pattern.h:72
std::conditional_t< sizeof...(U)==0, first_result, typename output_value_type< first_result, U... >::type > type
Definition: pipeline_pattern.h:126
std::tuple< Transformers... > transformers_type
Definition: pipeline_pattern.h:37
auto stage() const noexcept
Gets a transformer from the pipeline.
Definition: pipeline_pattern.h:83
Representation of pipeline pattern. Represents a pipeline with multiple chained transformers.
Definition: pipeline_pattern.h:34
typename internal::output_value_type< I, T >::type output_value_type
Definition: pipeline_pattern.h:132
pipeline_t(Transformers &&...others) noexcept
Constructs a pipeline with several transformers.
Definition: pipeline_pattern.h:44
auto invoke_all(T item) const
Definition: pipeline_pattern.h:51
Definition: pipeline_pattern.h:100
static constexpr bool is_pipeline
Definition: pipeline_pattern.h:108
typename std::enable_if_t< is_pipeline< T >, int > requires_pipeline
Definition: pipeline_pattern.h:111
std::decay_t< typename std::result_of< T(I)>::type > first_result
Definition: pipeline_pattern.h:122
std::decay_t< typename std::result_of< T(I)>::type > type
Definition: pipeline_pattern.h:117
auto transformers() const noexcept
Definition: pipeline_pattern.h:89
Definition: pipeline_pattern.h:116
auto operator()(T item) const
Definition: pipeline_pattern.h:63