tlx
FunctionChain< Functors > Class Template Reference

A FunctionChain is a chain of functors that can be folded to a single functors. More...

#include <function_chain.hpp>

Public Member Functions

 FunctionChain ()=default
 default constructor: empty functor chain. More...
 
 FunctionChain (const std::tuple< Functors... > &chain)
 Initialize the function chain with a given tuple of functions. More...
 
template<typename Functor >
auto push (const Functor &functor) const
 Add a functor to the end of the chain. More...
 
template<typename Functor >
auto operator& (const Functor &functor) const
 Add a functor to the end of the chain. More...
 
auto fold () const
 Build a single functor by "folding" the chain. More...
 
template<typename... Input>
auto operator() (Input &&...value) const
 Directly call the folded function chain with a value. More...
 

Static Public Attributes

static constexpr bool empty
 Is true if the FunctionChain is empty. More...
 
static constexpr size_t size
 Number of functors in the FunctionChain. More...
 

Private Member Functions

template<size_t... Is>
auto fold_chain (index_sequence< Is... >) const
 Auxilary function for "folding" the chain. More...
 

Private Attributes

std::tuple< Functors... > chain_
 Tuple of varying type that stores all functors. More...
 

Detailed Description

template<typename... Functors>
class tlx::FunctionChain< Functors >

A FunctionChain is a chain of functors that can be folded to a single functors.

All functors within the chain receive a single input value, which is the result of all preceding functors in the chain.

The FunctionChain basically consists of a tuple that contains functors of varying types.

Template Parameters
Input_Input to first functor functor.
FunctorsTypes of the different functors.

Definition at line 87 of file function_chain.hpp.

Constructor & Destructor Documentation

FunctionChain ( )
default

default constructor: empty functor chain.

FunctionChain ( const std::tuple< Functors... > &  chain)
inlineexplicit

Initialize the function chain with a given tuple of functions.

Parameters
chainTuple of functors.

Definition at line 98 of file function_chain.hpp.

Member Function Documentation

auto fold ( ) const
inline

Build a single functor by "folding" the chain.

Folding means that the chain is processed from front to back.

Returns
Single "folded" functor representing the chain.

Definition at line 135 of file function_chain.hpp.

auto fold_chain ( index_sequence< Is... >  ) const
inlineprivate

Auxilary function for "folding" the chain.

This is needed to send all functors as parameters to the function that folds them together.

Returns
Single "folded" functor representing the chain.

Definition at line 164 of file function_chain.hpp.

auto operator& ( const Functor &  functor) const
inline

Add a functor to the end of the chain.

Alias for fold().

Template Parameters
FunctorType of the functors.
Parameters
functorfunctor that should be added to the chain.
Returns
New chain containing the previous and new functor(s).

Definition at line 127 of file function_chain.hpp.

auto operator() ( Input &&...  value) const
inline

Directly call the folded function chain with a value.

Definition at line 143 of file function_chain.hpp.

auto push ( const Functor &  functor) const
inline

Add a functor to the end of the chain.

Template Parameters
FunctorType of the functors.
Parameters
functorfunctor that should be added to the chain.
Returns
New chain containing the previous and new functor(s).

Definition at line 111 of file function_chain.hpp.

Member Data Documentation

std::tuple<Functors...> chain_
private

Tuple of varying type that stores all functors.

Definition at line 155 of file function_chain.hpp.

constexpr bool empty
static

Is true if the FunctionChain is empty.

Definition at line 148 of file function_chain.hpp.

constexpr size_t size
static

Number of functors in the FunctionChain.

Definition at line 151 of file function_chain.hpp.


The documentation for this class was generated from the following file: