Lumiera
0.pre.03
»edit your freedom«
|
Go to the source code of this file.
Metaprogramming tools for transforming functor types.
Sometimes it is necessary to build and remould a function signature, e.g. for creating a functor or a closure based on an existing function of function pointer. This is a core task of functional programming, but sadly C++ in its current shape is still lacking in this area. (C++11 significantly improved this situation). As an pragmatic fix, we define here a collection of templates, specialising them in a very repetitive way for up to 9 function arguments. Doing so enables us to capture a function, access the return type and argument types as a typelist, eventually to manipulate them and re-build a different signature, or to create specifically tailored bindings.
If the following code makes you feel like vomiting, please look away, and rest assured: you aren't alone.
Definition in file function.hpp.
Classes | |
struct | _DetectSingleArgFunction< FUN > |
struct | _Fun< FUN, SEL > |
Helper for uniform access to function signature types. More... | |
struct | _Fun< FUN(C::*)> |
allow also to probe plain member fields, which may hold a functor More... | |
struct | _Fun< FUN, enable_if< has_FunctionOperator< FUN > > > |
Specialisation for function objects and lambdas. More... | |
struct | _Fun< RET(ARGS...) noexcept > |
Specialisation to strip noexcept from the signature. More... | |
struct | _Fun< RET(ARGS...)> |
Specialisation for a bare function signature. More... | |
struct | _Fun< RET(C::*)(ARGS...) const > |
Specialisation to handle member pointer to const function; indirectly this specialisation also handles lambdas, as redirected by the main template (via decltype ) More... | |
struct | _Fun< RET(C::*)(ARGS...) noexcept > |
Specialisation to deal with member pointer to noexcept function. More... | |
struct | _Fun< RET(C::*)(ARGS...)> |
Specialisation to deal with member pointer to function. More... | |
struct | _Fun< SIG & > |
Specialisation when using a function reference. More... | |
struct | _Fun< SIG && > |
Specialisation for passing a rvalue reference. More... | |
struct | _Fun< SIG * > |
Specialisation for using a function pointer. More... | |
struct | _Fun< SIG const & > |
Specialisation to strip spurious const for type analysis. More... | |
struct | BuildFunType< RET, ARGS > |
Build function types from given Argument types. More... | |
struct | BuildFunType< RET, Types< A1 > > |
struct | BuildFunType< RET, Types< A1, A2 > > |
struct | BuildFunType< RET, Types< A1, A2, A3 > > |
struct | BuildFunType< RET, Types< A1, A2, A3, A4 > > |
struct | BuildFunType< RET, Types< A1, A2, A3, A4, A5 > > |
struct | BuildFunType< RET, Types< A1, A2, A3, A4, A5, A6 > > |
struct | BuildFunType< RET, Types< A1, A2, A3, A4, A5, A6, A7 > > |
struct | BuildFunType< RET, Types< A1, A2, A3, A4, A5, A6, A7, A8 > > |
struct | BuildFunType< RET, Types< A1, A2, A3, A4, A5, A6, A7, A8, A9 > > |
struct | BuildFunType< RET, Types<> > |
struct | has_Sig< FUN, SIG, bool > |
Meta-function to check that some function like entity offers the expected signature. More... | |
struct | has_Sig< FUN, X, false > |
catch-all to prevent compilation failure for anything not function-like. More... | |
struct | InstancePlaceholder< TAR > |
Placeholder marker for a special argument position to be supplied later. More... | |
Typedefs | |
template<typename FUN > | |
using | _FunArg = typename _DetectSingleArgFunction< FUN >::Arg |
abbreviation for referring to a function's single Argument type | |
template<typename FUN > | |
using | _FunRet = typename _Fun< FUN >::Ret |
abbreviation for referring to a function's return type | |
template<typename FUN , uint a> | |
using | has_Arity = std::bool_constant< _Fun< FUN >::ARITY==a > |
template<typename FUN > | |
using | is_BinaryFun = has_Arity< FUN, 2 > |
template<typename FUN > | |
using | is_NullaryFun = has_Arity< FUN, 0 > |
template<typename FUN > | |
using | is_UnaryFun = has_Arity< FUN, 1 > |
Macros | |
#define | ASSERT_MEMBER_FUNCTOR(_EXPR_, _SIG_) |
Macro for a compile-time check to verify some member is present and comprises something invokable with a specific signature. More... | |
#define | ASSERT_VALID_SIGNATURE(_FUN_, _SIG_) |
Macro for a compile-time check to verify the given generic functors or lambdas expose some expected signature. More... | |
Functions | |
template<typename SIG , typename FUN > | |
constexpr auto | isFunMember (FUN) |
Helper to pick up a member field for verification. More... | |
template<class W , class TUP > | |
constexpr auto | lateBindInstance (W &instance, TUP &&invocation) |
Fix-up the arguments for a member-function invocation, allowing to inject the actual this instance into an existing argument sequence. More... | |
template<class W , class TAR > | |
constexpr TAR * | maybeInject (W &instance, InstancePlaceholder< TAR >) |
template<class W , typename X > | |
constexpr X | maybeInject (W &, X &&x) |
(default case: fall-through) | |
Namespaces | |
lib | |
Implementation namespace for support and library code. | |
#define ASSERT_VALID_SIGNATURE | ( | _FUN_, | |
_SIG_ | |||
) |
Macro for a compile-time check to verify the given generic functors or lambdas expose some expected signature.
Definition at line 256 of file function.hpp.
Referenced by Detector4StructuralChanges< PAR, LIS, assign >::~Detector4StructuralChanges().
#define ASSERT_MEMBER_FUNCTOR | ( | _EXPR_, | |
_SIG_ | |||
) |
Macro for a compile-time check to verify some member is present and comprises something invokable with a specific signature.
Definition at line 282 of file function.hpp.
Referenced by vault::gear::activity::_verify_usable_as_ExecutionContext(), and Worker< vault::gear::Scheduler::Setup >::isDead().
struct lib::meta::anonymous_namespace{function.hpp}::_DetectSingleArgFunction |
|
inline |
Helper to pick up a member field for verification.
SIG | signature of the function like entity expected |
FUN | address- or member-pointer, e.g. &Class::member |
Definition at line 272 of file function.hpp.
References lib::meta::isFunMember().
Referenced by lib::meta::isFunMember().
|
inline |
Fix-up the arguments for a member-function invocation, allowing to inject the actual this
instance into an existing argument sequence.
Definition at line 327 of file function.hpp.
References lib::meta::lateBindInstance().
Referenced by LateBindInstance_test::demonstrateUsage(), lib::meta::lateBindInstance(), LateBindInstance_test::verify_cornerCases(), and LateBindInstance_test::verify_forwarding().