17#ifndef TLX_META_FUNCTION_CHAIN_HEADER
18#define TLX_META_FUNCTION_CHAIN_HEADER
35 return [](
const auto& input)
mutable ->
auto {
46template <
typename Functor>
50 return [functor = functor](
const auto& input)
mutable ->
auto {
51 return functor(input);
63template <
typename Functor,
typename... MoreFunctors>
64auto call_chain(
const Functor& functor,
const MoreFunctors& ... rest) {
67 return [=, functor = functor](
const auto& input)
mutable ->
auto {
86template <
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>
142 template <
typename... Input>
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>
170template <
typename Functor>
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.
static constexpr bool empty
Is true if the FunctionChain is empty.
FunctionChain(const std::tuple< Functors... > &chain)
Initialize the function chain with a given tuple of functions.
FunctionChain()=default
default constructor: empty functor chain.
auto fold() const
Build a single functor by "folding" the chain.
auto operator()(Input &&... value) const
Directly call the folded function chain with a value.
std::tuple< Functors... > chain_
Tuple of varying type that stores all functors.
auto fold_chain(index_sequence< Is... >) const
Auxilary function for "folding" the chain.
auto operator&(const Functor &functor) const
Add a functor to the end of the chain.
static constexpr size_t size
Number of functors in the FunctionChain.