Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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:
6/2025 while this is the core of this feature, the implementation is still confusing and bears traces from being the first attempt at solving this problem, with a pre-C++11 feature set. Driven by other requirements, over time several variations were added, so that now the main functionality is now implemented twice, in a very similar way in BindToArgument. Actually, the latter seems much clearer, and possibly PApply could be rewritten into a front-end and delegate to BindToArgument... ////////////////////////////////////TICKET #1394

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

Public Types

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

Static Public Member Functions

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

Private Types

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

Member Typedef Documentation

◆ Args

template<typename SIG , typename VAL >
using Args = _Fun<SIG>::Args
private

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

◆ Ret

template<typename SIG , typename VAL >
using Ret = _Fun<SIG>::Ret
private

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

◆ ArgsList

template<typename SIG , typename VAL >
using ArgsList = Args::List
private

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

◆ ValList

template<typename SIG , typename VAL >
using ValList = VAL::List
private

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

◆ ValTypes

template<typename SIG , typename VAL >
using ValTypes = Types<ValList>::Seq
private

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

◆ LeftReduced

template<typename SIG , typename VAL >
using LeftReduced = Splice<ArgsList, ValList>::Back
private

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

◆ RightReduced

template<typename SIG , typename VAL >
using RightReduced = Splice<ArgsList, ValList, ROFFSET>::Front
private

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

◆ ArgsL

template<typename SIG , typename VAL >
using ArgsL = Types<LeftReduced>::Seq
private

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

◆ ArgsR

template<typename SIG , typename VAL >
using ArgsR = Types<RightReduced>::Seq
private

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

◆ TrailingPlaceholders

template<typename SIG , typename VAL >
using TrailingPlaceholders = func::PlaceholderTuple<LeftReduced>::List
private

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

◆ LeadingPlaceholders

template<typename SIG , typename VAL >
using LeadingPlaceholders = func::PlaceholderTuple<RightReduced>::List
private

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

◆ LeftReplaced

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

◆ RightReplaced

template<typename SIG , typename VAL >
using RightReplaced = Splice<ArgsList, LeadingPlaceholders, 0 >::List
private

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

◆ LeftReplacedTypes

template<typename SIG , typename VAL >
using LeftReplacedTypes = Types<LeftReplaced>::Seq
private

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

◆ RightReplacedTypes

template<typename SIG , typename VAL >
using RightReplacedTypes = Types<RightReplaced>::Seq
private

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

◆ IdxSelectorL

template<typename SIG , typename VAL >
template<class SRC , class TAR , size_t i>
using IdxSelectorL = PartiallyInitTuple<SRC, TAR, 0>::template IndexMapper<i>
private

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

◆ IdxSelectorR

template<typename SIG , typename VAL >
template<class SRC , class TAR , size_t i>
using IdxSelectorR = PartiallyInitTuple<SRC, TAR, ROFFSET>::template IndexMapper<i>
private

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

◆ BuildL

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

◆ BuildR

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

◆ 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 341 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 345 of file function-closure.hpp.

◆ LeftReducedFunc

template<typename SIG , typename VAL >
using LeftReducedFunc = function<typename BuildFunType<Ret,ArgsL>::Sig>

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

◆ RightReducedFunc

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

Member Enumeration Documentation

◆ anonymous enum

template<typename SIG , typename VAL >
anonymous enum
private
Enumerator
ARG_CNT 
VAL_CNT 
ROFFSET 

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

Member Function Documentation

◆ bindFront()

template<typename SIG , typename VAL >
static LeftReducedFunc bindFront ( SIG const f,
Tuple< ValTypes 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.
Note
BuildL, and consequently std::bind must take the arguments by-value. Any attempt towards »perfect-forwarding« would be potentially fragile and not worth the effort, since the optimiser sees the operation as a whole.
Todo:

2/2025 However, the LeftReplacedArgs could then possibly moved into the bind function, as could the functor, once we replace the Apply-template by STDLIB features.

5/2025 seems indeed we could perfect-forward everything into the binder object.

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

References lib::meta::func::bindArgTuple().

Referenced by FunctionComposition_test::check_partialApplication().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bindBack()

template<typename SIG , typename VAL >
static RightReducedFunc bindBack ( SIG const f,
Tuple< ValTypes 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, aligned to the right end.
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 383 of file function-closure.hpp.

References lib::meta::func::bindArgTuple().

Referenced by FunctionComposition_test::check_partialApplication().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:
+ Collaboration diagram for PApply< SIG, VAL >:

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