Go to the documentation of this file.
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>
144 return fold()(std::move(value...));
148 static constexpr
bool empty = (
sizeof ... (Functors) == 0);
151 static constexpr
size_t size =
sizeof ... (Functors);
155 std::tuple<Functors...>
chain_;
163 template <
size_t... Is>
170 template <
typename Functor>
186 #endif // !TLX_META_FUNCTION_CHAIN_HEADER
static constexpr bool empty
Is true if the FunctionChain is empty.
FunctionChain()=default
default constructor: empty functor chain.
A FunctionChain is a chain of functors that can be folded to a single functors.
std::tuple< Functors... > chain_
Tuple of varying type that stores all functors.
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.
auto push(const Functor &functor) const
Add a functor to the end of the chain.
auto operator()(Input &&... value) const
Directly call the folded function chain with a value.
auto fold() const
Build a single functor by "folding" the chain.
auto fold_chain(index_sequence< Is... >) const
Auxilary function for "folding" the chain.