tlx
Loading...
Searching...
No Matches
FunctionStack< Input_, Functors > Class Template Reference

A FunctionStack is a chain of functor that can be folded to a single functor (which is usually optimize by the compiler). More...

#include <function_stack.hpp>

Public Types

using Input
 

Public Member Functions

 FunctionStack ()=default
 Construct an empty FunctionStack.
 
 FunctionStack (const std::tuple< Functors... > &stack)
 Initialize the function stack with a given tuple of functors.
 
template<typename Functor >
auto push (const Functor &functor) const
 Add a functor function to the end of the stack.
 
template<typename Functor >
auto operator& (const Functor &functor) const
 Add a functor to the end of the stack.
 
auto fold () const
 Build a single functor by "folding" the stack.
 

Static Public Attributes

static constexpr bool empty
 Is true if the FunctionStack is empty.
 
static constexpr size_t size
 Number of functors on the FunctionStack.
 

Private Member Functions

template<size_t... Is>
auto fold_stack (index_sequence< Is... >) const
 Auxilary function for "folding" the stack.
 

Private Attributes

std::tuple< Functors... > stack_
 Tuple of varying type that stores all functor objects functions.
 

Detailed Description

template<typename Input_, typename... Functors>
class tlx::FunctionStack< Input_, Functors >

A FunctionStack is a chain of functor that can be folded to a single functor (which is usually optimize by the compiler).

All functors within the chain receive a single input value and a emitter function. The emitter function is used for chaining functors together by enabling items to pushed down the sequence. The single exception to this is the last functor, which receives no emitter, and hence usually stores the items somehow.

The FunctionStack basically consists of a tuple that contains functor objects of varying types.

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

Definition at line 90 of file function_stack.hpp.

Member Typedef Documentation

◆ Input

template<typename Input_ , typename... Functors>
using Input

Definition at line 93 of file function_stack.hpp.

Constructor & Destructor Documentation

◆ FunctionStack() [1/2]

template<typename Input_ , typename... Functors>
FunctionStack ( )
default

Construct an empty FunctionStack.

◆ FunctionStack() [2/2]

template<typename Input_ , typename... Functors>
FunctionStack ( const std::tuple< Functors... > & stack)
inlineexplicit

Initialize the function stack with a given tuple of functors.

Parameters
stackTuple of functor.

Definition at line 103 of file function_stack.hpp.

Member Function Documentation

◆ fold()

template<typename Input_ , typename... Functors>
auto fold ( ) const
inline

Build a single functor by "folding" the stack.

Folding means that the stack is processed from front to back and each emitter is composed using previous functors.

Returns
Single "folded" functor representing the whole stack.

Definition at line 141 of file function_stack.hpp.

◆ fold_stack()

template<typename Input_ , typename... Functors>
template<size_t... Is>
auto fold_stack ( index_sequence< Is... > ) const
inlineprivate

Auxilary function for "folding" the stack.

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

Returns
Single "folded" functor representing the stack.

Definition at line 162 of file function_stack.hpp.

◆ operator&()

template<typename Input_ , typename... Functors>
template<typename Functor >
auto operator& ( const Functor & functor) const
inline

Add a functor to the end of the stack.

Alias for push().

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

Definition at line 132 of file function_stack.hpp.

◆ push()

template<typename Input_ , typename... Functors>
template<typename Functor >
auto push ( const Functor & functor) const
inline

Add a functor function to the end of the stack.

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

Definition at line 116 of file function_stack.hpp.

Member Data Documentation

◆ empty

template<typename Input_ , typename... Functors>
bool empty
staticconstexpr

Is true if the FunctionStack is empty.

Definition at line 146 of file function_stack.hpp.

◆ size

template<typename Input_ , typename... Functors>
size_t size
staticconstexpr

Number of functors on the FunctionStack.

Definition at line 149 of file function_stack.hpp.

◆ stack_

template<typename Input_ , typename... Functors>
std::tuple<Functors...> stack_
private

Tuple of varying type that stores all functor objects functions.

Definition at line 153 of file function_stack.hpp.


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