tlx
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 = Input_
 

Public Member Functions

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

Static Public Attributes

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

Private Member Functions

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

Private Attributes

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

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

using Input = Input_

Definition at line 93 of file function_stack.hpp.

Constructor & Destructor Documentation

FunctionStack ( )
default

Construct an empty FunctionStack.

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

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.

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.

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.

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

constexpr bool empty
static

Is true if the FunctionStack is empty.

Definition at line 146 of file function_stack.hpp.

constexpr size_t size
static

Number of functors on the FunctionStack.

Definition at line 149 of file function_stack.hpp.

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: