![]() |
Lumiera 0.pre.04
»edit your freedom«
|
Partial function application and building a complete function closure. More...
Go to the source code of this file.
Partial function application and building a complete function closure.
These are features known from functional programming and are here implemented based on std::bind, to support especially the case when some arguments of a function are known at an earlier stage, and should thus be »baked in«, while further arguments will be supplied later, for the actual invocation. This implies to close (and thus bind) some arguments immediately, while keeping other arguments open to — so the result of this operation is again a function, albeit with fewer arguments. Additionally, we allow for composing (chaining) of two functions.
the implementation is able to handle partial application with N arguments, but currently we need just one argument, thus only this case was wrapped up into a convenient functions func::applyFirst and func::applyLast
2/25 note that there is a bind_front in C++20 and C++23 will provide a bind_back helper, which would provide the implementation fully in accordance with current expectations (including move, constexpr); if we choose to retain a generic function-style front-end, it should be aligned with these standard facilities. We might want to retain a simple generic interface especially for binding some selected argument, which handles the intricacies of storing the functor.
6/25 note however that the full-fledged partial function application is a relevant core feature and is used in the NodeBuilder (see tuple-closure.hpp). Further improvement of the implementation is thus mandated... ////////////////////////////////////TICKET #1394
Definition in file function-closure.hpp.
#include "lib/meta/function.hpp"#include "lib/meta/tuple-helper.hpp"#include "lib/util.hpp"#include <functional>#include <utility>#include <tuple>Namespaces | |
| namespace | lib |
| Implementation namespace for support and library code. | |
| namespace | lib::meta |
| namespace | lib::meta::func |
| namespace | lib::meta::func::anonymous_namespace{function-closure.hpp} |
Classes | |
| struct | PlaceholderTuple< TYPES, i > |
| Build a list of standard function argument placeholder types. More... | |
| struct | PlaceholderTuple< Node< X, TAIL >, i > |
| struct | PlaceholderTuple< Nil, i > |
| struct | PartiallyInitTuple< SRC, TAR, start > |
| Builder for a tuple instance, where only some ctor parameters are supplied, while the remaining arguments will be default constructed. More... | |
| struct | PartiallyInitTuple< SRC, TAR, start >::IndexMapper< idx, doPick > |
| struct | PartiallyInitTuple< SRC, TAR, start >::IndexMapper< idx, false > |
| struct | AdaptInvokable< ARGS > |
| Helper to package a given invokable, so that it has a well defined function signature. More... | |
| class | 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. More... | |
| class | BindToArgument< SIG, X, pos > |
| Bind a specific argument to an arbitrary value. More... | |
| struct | _Chain< FUN1, FUN2 > |
Functions | |
| template<class FUN , class TUP > requires (tuple_like<remove_reference_t<TUP>>) | |
| auto | bindArgTuple (FUN &&fun, TUP &&tuple) |
| Base technique: build a binder with arguments from a tuple. | |
| template<class TYPES , class FUN > | |
| auto | buildInvokableWrapper (FUN &&fun) |
| Workaround to yield std::bind functors with a clearly defined function signature. | |
| template<typename FUN , typename TERM > | |
| auto | bindFirst (FUN &&f, TERM &&arg) |
| bind (close) the first function argument to an arbitrary term. | |
| template<typename FUN , typename TERM > | |
| auto | bindLast (FUN &&f, TERM &&arg) |
| template<typename FUN1 , typename FUN2 > | |
| auto | chained (FUN1 &&f1, FUN2 &&f2) |
| build a functor chaining the given functions: feed the result of f1 into f2. | |
| struct lib::meta::func::anonymous_namespace{function-closure.hpp}::PlaceholderTuple |
Collaboration diagram for PlaceholderTuple< TYPES, i >:| struct lib::meta::func::anonymous_namespace{function-closure.hpp}::PlaceholderTuple< Node< X, TAIL >, i > |
| Class Members | ||
|---|---|---|
| typedef List | TailPlaceholders | |
| typedef Node< _Placeholder< i >, TailPlaceholders > | List | |
Collaboration diagram for PlaceholderTuple< Node< X, TAIL >, i >: