17 #ifndef TLX_META_FUNCTION_CHAIN_HEADER 18 #define TLX_META_FUNCTION_CHAIN_HEADER 29 namespace meta_detail {
35 return [](
const auto& input)
mutable ->
auto {
46 template <
typename Functor>
50 return [functor = functor](
const auto& input)
mutable ->
auto {
51 return functor(input);
63 template <
typename Functor,
typename... MoreFunctors>
64 auto call_chain(
const Functor& functor,
const MoreFunctors& ... rest) {
67 return [=, functor = functor](
const auto& input)
mutable ->
auto {
86 template <
typename... Functors>
110 template <
typename Functor>
111 auto push(
const Functor& functor)
const {
114 std::tuple_cat(chain_, std::make_tuple(functor)));
126 template <
typename Functor>
127 auto operator & (
const Functor& functor)
const {
return push(functor); }
142 template <
typename... Input>
143 auto operator () (Input&& ...
value)
const {
144 return fold()(std::move(
value...));
148 static constexpr
bool empty = (
sizeof ... (Functors) == 0);
151 static constexpr
size_t size =
sizeof ... (Functors);
163 template <
size_t... Is>
170 template <
typename Functor>
186 #endif // !TLX_META_FUNCTION_CHAIN_HEADER
FunctionChain(const std::tuple< Functors... > &chain)
Initialize the function chain with a given tuple of functions.
std::tuple< Functors... > chain_
Tuple of varying type that stores all functors.
A FunctionChain is a chain of functors that can be folded to a single functors.
auto push(const Functor &functor) const
Add a functor to the end of the chain.
auto fold() const
Build a single functor by "folding" the chain.
auto fold_chain(index_sequence< Is... >) const
Auxilary function for "folding" the chain.