Lumiera  0.pre.03
»edit your freedom«
PApply< SIG, VAL > Class Template Reference

#include "lib/meta/function-closure.hpp"

Description

template<typename SIG, typename VAL>
class lib::meta::func::PApply< SIG, VAL >

Partial function application Takes a function and a value tuple, using the latter to close function arguments either from the front (left) or aligned to the end of the function argument list.

Result is a "reduced" function, expecting only the remaining "un-closed" arguments at invocation.

Template Parameters
SIGsignature of the function to be closed, either as function reference type or std::function object
VALtype sequence describing the tuple of values used for closing arguments
Note
the construction of this helper template does not verify or match types to the signature. In case of mismatch, you'll get a compilation failure from std::bind (which can be confusing)
Todo:
11/2023 started with modernising these functor utils. The most relevant bindFirst() / bindLast() operations do no longer rely on the PApply template. There is however the more general case of binding multiple arguments, which is still used at a few places. Possibly PApply should be rewritten from scratch, using modern tooling.

Definition at line 567 of file function-closure.hpp.

Public Types

typedef function< typename BuildFunType< Ret, ArgsL >::Sig > LeftReducedFunc
 
typedef function< typename BuildFunType< Ret, ArgsR >::Sig > RightReducedFunc
 

Static Public Member Functions

static RightReducedFunc bindBack (SIG const &f, Tuple< ValTypes > const &arg)
 do a partial function application, closing the last arguments
f(a,b,c)->res + (b,c) yields f(a)->res More...
 
static LeftReducedFunc bindFront (SIG const &f, Tuple< ValTypes > const &arg)
 do a partial function application, closing the first arguments
f(a,b,c)->res + (a,b) yields f(c)->res More...
 

Private Types

enum  {
  ARG_CNT = count<ArgsList>::value,
  VAL_CNT = count<ValList> ::value,
  ROFFSET = (VAL_CNT < ARG_CNT)? ARG_CNT-VAL_CNT : 0
}
 
typedef _Fun< SIG >::Args Args
 
typedef Types< LeftReduced >::Seq ArgsL
 
typedef Args::List ArgsList
 
typedef Types< RightReduced >::Seq ArgsR
 
using BuildL = TupleConstructor< LeftReplacedTypes, IdxSelectorL >
 
using BuildR = TupleConstructor< RightReplacedTypes, IdxSelectorR >
 
template<class SRC , class TAR , size_t i>
using IdxSelectorL = typename PartiallyInitTuple< SRC, TAR, 0 >::template IndexMapper< i >
 
template<class SRC , class TAR , size_t i>
using IdxSelectorR = typename PartiallyInitTuple< SRC, TAR, ROFFSET >::template IndexMapper< i >
 
typedef func::PlaceholderTuple< RightReduced >::List LeadingPlaceholders
 
typedef Splice< ArgsList, ValList >::Back LeftReduced
 
typedef Splice< ArgsList, TrailingPlaceholders, VAL_CNT >::List LeftReplaced
 
using LeftReplacedArgs = Tuple< LeftReplacedTypes >
 Tuple to hold all argument values, starting from left. More...
 
typedef Types< LeftReplaced >::Seq LeftReplacedTypes
 
typedef _Fun< SIG >::Ret Ret
 
typedef Splice< ArgsList, ValList, ROFFSET >::Front RightReduced
 
typedef Splice< ArgsList, LeadingPlaceholders, 0 >::List RightReplaced
 
using RightReplacedArgs = Tuple< RightReplacedTypes >
 Tuple to hold all argument values, aligned to the end of the function argument list. More...
 
typedef Types< RightReplaced >::Seq RightReplacedTypes
 
typedef func::PlaceholderTuple< LeftReduced >::List TrailingPlaceholders
 
typedef VAL::List ValList
 
typedef Types< ValList >::Seq ValTypes
 

Member Typedef Documentation

◆ LeftReplacedArgs

Tuple to hold all argument values, starting from left.

Any remaining positions behind the substitute values are occupied by binding placeholders

Definition at line 617 of file function-closure.hpp.

◆ RightReplacedArgs

Tuple to hold all argument values, aligned to the end of the function argument list.

Any remaining positions before the substitute values are occupied by binding placeholders

Definition at line 621 of file function-closure.hpp.

Member Function Documentation

◆ bindFront()

static LeftReducedFunc bindFront ( SIG const &  f,
Tuple< ValTypes > const &  arg 
)
inlinestatic

do a partial function application, closing the first arguments
f(a,b,c)->res + (a,b) yields f(c)->res

Parameters
ffunction, function pointer or functor
argvalue tuple, used to close function arguments starting from left
Returns
new function object, holding copies of the values and using them at the closed arguments; on invocation, only the remaining arguments need to be supplied.

Definition at line 638 of file function-closure.hpp.

◆ bindBack()

static RightReducedFunc bindBack ( SIG const &  f,
Tuple< ValTypes > const &  arg 
)
inlinestatic

do a partial function application, closing the last arguments
f(a,b,c)->res + (b,c) yields f(a)->res

Parameters
ffunction, function pointer or functor
argvalue tuple, used to close function arguments starting from right
Returns
new function object, holding copies of the values and using them at the closed arguments; on invocation, only the remaining arguments need to be supplied.

Definition at line 653 of file function-closure.hpp.

+ Collaboration diagram for PApply< SIG, VAL >:

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