|
Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
|
A general-purpose static-polymorphic function wrapper via jau::function<R(A...)>. More...
Namespaces | |
| namespace | jau::func |
Classes | |
| class | jau::func::capref_target_t< R, I, A > |
| func::capref_target_t implementation for functions using a reference to a captured value, identifiable as func::target_type::capref via jau::function<R(A...)>::type(). More... | |
| class | jau::func::capval_target_t< R, I, A > |
| func::capval_target_t implementation for functions using a copy of a captured value, identifiable as func::target_type::capval via jau::function<R(A...)>::type(). More... | |
| class | jau::func::delegate_t< R, A > |
| Delegated target function object, providing a fast path target function invocation. More... | |
| class | jau::func::free_target_t< R, A > |
| func::free_target_t implementation for free functions, identifiable as func::target_type::free via jau::function<R(A...)>::type(). More... | |
| class | jau::function< Signature > |
| Class template jau::function is a general-purpose static-polymorphic function wrapper. More... | |
| class | jau::function< R(A...)> |
| Class template jau::function is a general-purpose static-polymorphic function wrapper. More... | |
| class | jau::func::lambda_target_t< R, L, A > |
| func::lambda_target_t implementation for lambda closures, identifiable as func::target_type::lambda via jau::function<R(A...)>::type(). More... | |
| class | jau::func::member_target_t< R, C0, C1, A > |
| func::member_target_t implementation for class member functions, identifiable as func::target_type::member via jau::function<R(A...)>::type(). More... | |
| class | jau::func::null_target_t< R, A > |
| func::null_target_t implementation for no function. More... | |
| class | jau::func::std_target_t< R, A > |
| func::std_target_t implementation for std::function instances, identifiable as func::target_type::std via jau::function<R(A...)>::type(). More... | |
| class | jau::func::target_t< R, A > |
| func::target_t pure-virtual interface for jau::function. More... | |
| class | jau::func::ylambda_target_t< R, L, A > |
| func::ylambda_target_t is a Y combinator and deducing this implementation for lambda closures usable for recursive algorithms. More... | |
Functions | |
| template<typename R , typename I , typename... A> | |
| jau::function< R(A...)> | jau::bind_capref (I *data_ptr, R(*func)(I *, A...)) noexcept |
| Bind given data by passing the captured reference (pointer) to the value and non-void function to an anonymous function using func::capref_target_t. More... | |
| template<typename I , typename... A> | |
| jau::function< void(A...)> | jau::bind_capref (I *data_ptr, void(*func)(I *, A...)) noexcept |
| Bind given data by passing the captured reference (pointer) to the value and void function to an anonymous function using func::capref_target_t. More... | |
| template<typename R , typename I , typename... A> | |
| jau::function< R(A...)> | jau::bind_capval (const I &data, R(*func)(I &, A...)) noexcept |
| Bind given data by copying the captured value and the given non-void function to an anonymous function using func::capval_target_t. More... | |
| template<typename I , typename... A> | |
| jau::function< void(A...)> | jau::bind_capval (const I &data, void(*func)(I &, A...)) noexcept |
| Bind given data by copying the captured value and the given void function to an anonymous function using func::capval_target_t. More... | |
| template<typename R , typename I , typename... A> | |
| jau::function< R(A...)> | jau::bind_capval (I &&data, R(*func)(I &, A...)) noexcept |
| Bind given data by moving the captured value and copying the given non-void function to an anonymous function using func::capval_target_t. More... | |
| template<typename I , typename... A> | |
| jau::function< void(A...)> | jau::bind_capval (I &&data, void(*func)(I &, A...)) noexcept |
| Bind given data by moving the captured value and copying the given void function to an anonymous function using func::capval_target_t. More... | |
| template<typename R , typename... A> | |
| jau::function< R(A...)> | jau::bind_free (R(*func)(A...)) noexcept |
| Bind given non-void free-function to an anonymous function using func::free_target_t. More... | |
| template<typename... A> | |
| jau::function< void(A...)> | jau::bind_free (void(*func)(A...)) noexcept |
| Bind given void free-function to an anonymous function using func::free_target_t. More... | |
| template<typename R , typename C , typename... A> | |
| jau::function< R(A...)> | jau::bind_member (C *base, R(C::*mfunc)(A...)) noexcept |
| Bind given class instance and non-void member function to an anonymous function using func_member_targer_t. More... | |
| template<typename C , typename... A> | |
| jau::function< void(A...)> | jau::bind_member (C *base, void(C::*mfunc)(A...)) noexcept |
| Bind given class instance and void member function to an anonymous function using func_member_targer_t. More... | |
| template<typename R , typename C0 , typename C1 , typename... A> | |
| jau::function< R(A...)> | jau::bind_member (C1 *base, R(C0::*mfunc)(A...)) noexcept |
| Bind given class instance and non-void member function to an anonymous function using func_member_targer_t. More... | |
| template<typename C0 , typename C1 , typename... A> | |
| jau::function< void(A...)> | jau::bind_member (C1 *base, void(C0::*mfunc)(A...)) noexcept |
| Bind given class instance and void member function to an anonymous function using func_member_targer_t. More... | |
| template<typename R , typename... A> | |
| jau::function< R(A...)> | jau::bind_std (uint64_t id, std::function< R(A...)> func) noexcept |
| Bind given non-void std::function to an anonymous function using func::std_target_t. More... | |
| template<typename... A> | |
| jau::function< void(A...)> | jau::bind_std (uint64_t id, std::function< void(A...)> func) noexcept |
| Bind given void std::function to an anonymous function using func::std_target_t. More... | |
| constexpr uint32_t | jau::number (const func::target_type rhs) noexcept |
| template<class R , class... A> | |
| bool | jau::operator!= (const function< R(A...)> &lhs, std::nullptr_t) noexcept |
| Unequal operator of jau::function<R(A...)> with a right-hand-side nullptr. More... | |
| template<typename Rl , typename... Al, template< typename... > typename Fl = function, typename Rr , typename... Ar, template< typename... > typename Fr = function> | |
| bool | jau::operator!= (const function< Rl(Al...)> &lhs, const function< Rr(Ar...)> &rhs) noexcept |
| Unequal operator using two jau::function<R(A...)> types for both arguments. More... | |
| template<class R , class... A> | |
| bool | jau::operator!= (std::nullptr_t, const function< R(A...)> &rhs) noexcept |
| Unequal operator of jau::function<R(A...)> with a left-hand-side nullptr. More... | |
| template<class R , class... A> | |
| bool | jau::operator== (const function< R(A...)> &lhs, std::nullptr_t) noexcept |
| Equal operator of jau::function<R(A...)> with a right-hand-side nullptr. More... | |
| template<typename Rl , typename... Al, template< typename... > class Fl = function, typename Rr , typename... Ar, template< typename... > class Fr = function, std::enable_if_t< !std::is_same_v< Fl< Rl(Al...)>, Fr< Rr(Ar...)> >, bool > = true> | |
| bool | jau::operator== (const function< Rl(Al...)> &lhs, const function< Rr(Ar...)> &rhs) noexcept |
| Equal operator using different jau::function<R(A...)> return and argument types for both arguments, always returns false. More... | |
| template<class R , class... A> | |
| bool | jau::operator== (std::nullptr_t, const function< R(A...)> &rhs) noexcept |
| Equal operator of jau::function<R(A...)> with a left-hand-side nullptr. More... | |
| std::string | jau::to_string (const func::target_type v) noexcept |
A general-purpose static-polymorphic function wrapper via jau::function<R(A...)>.
Supporting general-purpose polymorphic function wrapper via jau::function<R(A...)>.
Similar to std::function, jau::function<R(A...)> stores any callable target function solely described by its return type R and arguments types A... from any source, e.g. free functions, capturing and non-capturing lambda function, member functions.
jau::function<R(A...)> supports equality operations for all func::target_type source types, allowing to manage container of jau::functions, see limitations below.
If a jau::function contains no target, see jau::function<R(A...)>::is_null(), it is empty. Invoking the target of an empty jau::function is a no-operation and has no side effects.
jau::function satisfies the requirements of CopyConstructible, CopyAssignable, MoveConstructible and MoveAssignable.
Compared to std::function<R(A...)>, jau::function<R(A...)>
noexcept, except for the user given function invocationInstances of jau::function can store, copy, move and invoke any of its callable targets
jau::function<R(A...)> holds the static polymorphic target function delegate_t<R, A...>,
which itself completely holds up to 24 bytes sized TriviallyCopyable target function objects to avoiding cache misses.
The following table shows the full memory footprint of the target function delegate_t<R, A...> storage,
which equals to jau::function<R(A...)> memory size as it only contains the instance of delegate_t<R, A...>.
| Type | Signature | Target Function Size | delegate_t<R, A...> Size | Heap Size | Total Size | TriviallyCopyable |
|---|---|---|---|---|---|---|
| free | function<free, void ()> | 8 | 48 | 0 | 48 | true |
| member | function<member, int (int)> | 16 | 48 | 0 | 48 | true |
| lambda_plain | function<lambda, int (int)> | 24 | 48 | 0 | 48 | true |
| lambda_ref | function<lambda, int (int)> | 24 | 48 | 0 | 48 | true |
| lambda_copy | function<lambda, int (int)> | 24 | 48 | 0 | 48 | true |
| ylambda_plain | function<ylambda, int (int)> | 24 | 48 | 0 | 48 | true |
| capval (small) | function<capval, int (int)> | 16 | 48 | 0 | 48 | true |
| capval (big) | function<capval, int (int)> | 48 | 48 | 48 | 96 | true |
| capref | function<capref, int (int)> | 16 | 48 | 0 | 48 | true |
Memory sizes are in bytes, data collected on a GNU/Linux arm64 system.
The detailed memory footprint can queried at runtime, see implementation of jau::function<R(A...)>::function::toString().
Static polymorphism is achieved by constructing the delegate_t<R, A...> instance via their func::target_type specific factories, see mapping at func::target_type.
For example the static func::member_target_t::delegate constructs its specific delegate_t<R, A...> by passing its data and required functions to func::delegate_t<R, A...>::make.
The latter is an overloaded template for trivial and non-trivial types and decides which memory is being used, e.g. the internal 24 bytes memory cache or heap if not fitting.
To support lambda identity for the equality operator, jau::type_info is being used either with Runtime Type Information (RTTI) if enabled or using Compile time type information (CTTI), see limitations below.
A detailed API usage is covered within test_functional.hpp and test_functional_perf.hpp, see function test00_usage().
Let's assume we like to bind to the following function prototype bool func(int), which results to jau::function<bool(int)>:
jau::bind_free(R(*func)(A...)) jau::bind_member(C *base, R(C::*mfunc)(A...)) bool(*)(int) function auto function<R(A...)>::delegate_type jau::bind_capref(I* data_ptr, R(*func)(I*, A...)) jau::bind_capval(const I& data, R(*func)(I&, A...))jau::bind_capval(I&& data, R(*func)(I&, A...)) jau::bind_std(uint64_t id, std::function<R(A...)> func) gcc or non clang compilerDue to limitations of jau::make_ctti<R, L, A...>(), not using RTTI on gcc or non clang compiler will erroneously mistake different lambda functions defined within one function and using same function prototype R<A...> to be the same.
jau::type_info::limited_lambda_id will expose the potential limitation.
See CTTI lambda name limitations and limitations of jau::type_info.
Similar to std::function, jau::function<R(A...)> stores any callable target function solely described by its return type R and arguments types A... from any source, e.g. free functions, capturing and non-capturing lambda function, member functions,
jau::function<R(A...)> supports equality operations for all func::target_t source types, allowing to manage container of jau::functions.
See limitations below.
If a jau::function contains no target, see jau::function<R(A...)>::is_null(), it is empty. Invoking the target of an empty jau::function is a no-operation and has no side effects.
jau::function satisfies the requirements of CopyConstructible and CopyAssignable.
Compared to std::function<R(A...)>, jau::function<R(A...)>
noexcept, except for the user given function invocation.Instances of jau::function can store, copy, and invoke any of its callable targets
A detailed API usage is covered within test_functional01.cpp, see function test00_usage().
Let's assume we like to bind to the following function prototype bool func(int), which results to jau::function<bool(int)>:
jau::function<R(A...)> jau::bind_free(R(*func)(A...)) jau::function<R(A...)> jau::bind_member(C *base, R(C::*mfunc)(A...)) jau::function<R(A...)> jau::bind_capref(I* data_ptr, R(*func)(I*, A...)) jau::function<R(A...)> jau::bind_capval(const I& data, R(*func)(I&, A...))jau::function<R(A...)> jau::bind_capval(I&& data, R(*func)(I&, A...)) function<R(A...)> jau::bind_std(uint64_t id, std::function<R(A...)> func) gcc or non clang compilerDue to limitations of jau::make_ctti<R, L, A...>(), not using RTTI on gcc or non clang compiler will erroneously mistake different lambda functions defined within one function and using same function prototype R<A...> to be the same.
jau::type_info::limited_lambda_id will expose the potential limitation.
See CTTI lambda name limitations and limitations of jau::type_info.
A capturing lambda in C++11 produces decoration code accessing the captured elements,
i.e. an anonymous helper class.
Due to this fact, the return type is an undefined lambda specific and hence std::function didn't support it when specified, probably.
template<typename R, typename C, typename... A> inline function<R(A...)> bind_member(C *base, R(C::*mfunc)(A...)) { return ClassFunction<R, A...>( (void*)base, (void*)(*((void**)&mfunc)), [&](A... args)->R{ (base->*mfunc)(args...); }); ^ | Capturing lambda function-pointer are undefined! }
Capturing lambdas are supported by jau::function using func::lambda_target_t via constructor `template<typename L> function(L func)`, see above.
|
strong |
func::target_type identifier for the target function delegate_t<R, A...> object, exposed by jau::function<R(A...)>::type().
| Enumerator | |
|---|---|
| null | Denotes a func::null_target_t. |
| member | Denotes a func::member_target_t. |
| free | Denotes a func::free_target_t. |
| lambda | Denotes a func::lambda_target_t. |
| ylambda | Denotes a func::ylambda_target_t. |
| capval | Denotes a func::capval_target_t. |
| capref | Denotes a func::capref_target_t. |
| std | Denotes a func::std_target_t. |
| null | Denotes a func::null_target_t. |
| member | Denotes a func::member_target_t. |
| free | Denotes a func::free_target_t. |
| lambda | Denotes a func::lambda_target_t. |
| capval | Denotes a func::capval_target_t. |
| capref | Denotes a func::capref_target_t. |
| std | Denotes a func::std_target_t. |
Definition at line 341 of file functional.hpp.
|
strong |
func::target_type identifier for specializations of func::target_t used by jau::function<R(A...)>::type().
| Enumerator | |
|---|---|
| null | Denotes a func::null_target_t. |
| member | Denotes a func::member_target_t. |
| free | Denotes a func::free_target_t. |
| lambda | Denotes a func::lambda_target_t. |
| ylambda | Denotes a func::ylambda_target_t. |
| capval | Denotes a func::capval_target_t. |
| capref | Denotes a func::capref_target_t. |
| std | Denotes a func::std_target_t. |
| null | Denotes a func::null_target_t. |
| member | Denotes a func::member_target_t. |
| free | Denotes a func::free_target_t. |
| lambda | Denotes a func::lambda_target_t. |
| capval | Denotes a func::capval_target_t. |
| capref | Denotes a func::capref_target_t. |
| std | Denotes a func::std_target_t. |
Definition at line 277 of file functional2.hpp.
|
constexprnoexcept |
|
noexcept |
|
noexcept |
Equal operator using different jau::function<R(A...)> return and argument types for both arguments, always returns false.
Equal operator using same jau::function<R(A...)> return and argument types for both arguments, returning actual result of equality operation.
| Rl | left function return type |
| Al | left function arguments |
| Fl | left function Fl<Rl(<Al...)> |
| Rr | right function return type |
| Ar | right function arguments |
| Fr | right function Fr<Rr(<Ar...)> |
| lhs | left function Fl<Rl(<Al...)> |
| rhs | right function Fr<Rr(<Ar...)> |
| Rl | left function return type |
| Al | left function arguments |
| Fl | left function Fl<Rl(<Al...)> |
| Rr | right function return type |
| Ar | right function arguments |
| Fr | right function Fr<Rr(<Ar...)> |
| lhs | left function Fl<Rl(<Al...)> |
| rhs | right function Fr<Rr(<Ar...)> |
Definition at line 1518 of file functional.hpp.
|
noexcept |
Unequal operator using two jau::function<R(A...)> types for both arguments.
| Rl | left function return type |
| Al | left function arguments |
| Fl | left function Fl<Rl(<Al...)> |
| Rr | right function return type |
| Ar | right function arguments |
| Fr | right function Fr<Rr(<Ar...)> |
| lhs | left function Fl<Rl(<Al...)> |
| rhs | right function Fr<Rr(<Ar...)> |
Definition at line 1563 of file functional.hpp.
|
noexcept |
Equal operator of jau::function<R(A...)> with a right-hand-side nullptr.
| R | left function return type |
| A | left function arguments |
| lhs | left function |
!lhs negated function bool operator. Definition at line 1574 of file functional.hpp.
|
noexcept |
Unequal operator of jau::function<R(A...)> with a right-hand-side nullptr.
| R | left function return type |
| A | left function arguments |
| lhs | left function |
lhs function bool operator. Definition at line 1585 of file functional.hpp.
|
noexcept |
Equal operator of jau::function<R(A...)> with a left-hand-side nullptr.
| R | right function return type |
| A | right function arguments |
| rhs | right function |
!lhs negated function bool operator. Definition at line 1596 of file functional.hpp.
|
noexcept |
Unequal operator of jau::function<R(A...)> with a left-hand-side nullptr.
| R | right function return type |
| A | right function arguments |
| rhs | right function |
lhs function bool operator. Definition at line 1607 of file functional.hpp.
|
inlinenoexcept |
Bind given class instance and non-void member function to an anonymous function using func_member_targer_t.
| R | function return type |
| C0 | class type holding the member-function |
| C1 | class derived from C0 or C0 of this base-pointer used to invoke the member-function |
| A | function arguments |
| base | class instance this pointer |
| mfunc | member-function with R return value and A... arguments. |
Definition at line 1627 of file functional.hpp.
|
inlinenoexcept |
Bind given class instance and non-void member function to an anonymous function using func_member_targer_t.
| R | function return type |
| C | class type holding the member-function and of this base pointer |
| A | function arguments |
| base | class instance this pointer |
| mfunc | member-function with R return value and A... arguments. |
Definition at line 1647 of file functional.hpp.
|
inlinenoexcept |
Bind given class instance and void member function to an anonymous function using func_member_targer_t.
| C0 | class type holding the member-function |
| C1 | class derived from C0 or C0 of this base-pointer used to invoke the member-function |
| A | function arguments |
| base | class instance this pointer |
| mfunc | member-function with A... arguments. |
Definition at line 1667 of file functional.hpp.
|
inlinenoexcept |
Bind given class instance and void member function to an anonymous function using func_member_targer_t.
| C | class type holding the member-function and of this base pointer |
| A | function arguments |
| base | class instance this pointer |
| mfunc | member-function with A... arguments. |
Definition at line 1686 of file functional.hpp.
|
inlinenoexcept |
Bind given non-void free-function to an anonymous function using func::free_target_t.
| R | function return type |
| A | function arguments |
| func | free-function with R return value and A... arguments. |
Definition at line 1704 of file functional.hpp.
|
inlinenoexcept |
Bind given void free-function to an anonymous function using func::free_target_t.
| A | function arguments |
| func | free-function with A... arguments. |
Definition at line 1721 of file functional.hpp.
|
inlinenoexcept |
Bind given data by copying the captured value and the given non-void function to an anonymous function using func::capval_target_t.
const I& data will be copied into func::capval_target_t and hence captured by-copy.
The function invocation will have the reference of the copied data being passed to the target function for efficiency.
| R | function return type |
| I | typename holding the captured data used by the function |
| A | function arguments |
| data | data type instance holding the captured data |
| func | function with R return value and A... arguments. |
const I& data will be copied into func::capval_target_t and hence captured by copy.
The function invocation will have the reference of the copied data being passed to the target function for efficiency.
| R | function return type |
| I | typename holding the captured data used by the function |
| A | function arguments |
| data | data type instance holding the captured data |
| func | function with R return value and A... arguments. |
Definition at line 1745 of file functional.hpp.
|
inlinenoexcept |
Bind given data by copying the captured value and the given void function to an anonymous function using func::capval_target_t.
const I& data will be copied into func::capval_target_t and hence captured by-copy.
The function invocation will have the reference of the copied data being passed to the target function for efficiency.
| I | typename holding the captured data used by the function |
| A | function arguments |
| data | data type instance holding the captured data |
| func | function with A... arguments. |
const I& data will be copied into func::capval_target_t and hence captured by copy.
The function invocation will have the reference of the copied data being passed to the target function for efficiency.
| I | typename holding the captured data used by the function |
| A | function arguments |
| data | data type instance holding the captured data |
| func | function with A... arguments. |
Definition at line 1768 of file functional.hpp.
|
inlinenoexcept |
Bind given data by moving the captured value and copying the given non-void function to an anonymous function using func::capval_target_t.
I&& data will be moved into func::capval_target_t.
The function invocation will have the reference of the moved data being passed to the target function for efficiency.
| R | function return type |
| I | typename holding the captured data used by the function |
| A | function arguments |
| data | data type instance holding the captured data |
| func | function with R return value and A... arguments. |
Definition at line 1792 of file functional.hpp.
|
inlinenoexcept |
Bind given data by moving the captured value and copying the given void function to an anonymous function using func::capval_target_t.
I&& data will be moved into func::capval_target_t.
The function invocation will have the reference of the moved data being passed to the target function for efficiency.
| I | typename holding the captured data used by the function |
| A | function arguments |
| data | data type instance holding the captured data |
| func | function with A... arguments. |
Definition at line 1815 of file functional.hpp.
|
inlinenoexcept |
Bind given data by passing the captured reference (pointer) to the value and non-void function to an anonymous function using func::capref_target_t.
The function invocation will have the reference of the data being passed to the target function.
| R | function return type |
| I | typename holding the captured data used by the function |
| A | function arguments |
| data_ptr | data type reference to instance holding the captured data |
| func | function with R return value and A... arguments. |
Definition at line 1837 of file functional.hpp.
|
inlinenoexcept |
Bind given data by passing the captured reference (pointer) to the value and void function to an anonymous function using func::capref_target_t.
The function invocation will have the reference of the data being passed to the target function.
| I | typename holding the captured data used by the function |
| A | function arguments |
| data_ptr | data type reference to instance holding the captured data |
| func | function with A... arguments. |
Definition at line 1858 of file functional.hpp.
|
inlinenoexcept |
Bind given non-void std::function to an anonymous function using func::std_target_t.
Notable, instance is holding the given unique uint64_t identifier to allow implementing the equality operator w/o RTTI, not supported by std::function.
| R | function return type |
| A | function arguments |
| func | free-function with R return value and A... arguments. |
Definition at line 1879 of file functional.hpp.
|
inlinenoexcept |
Bind given void std::function to an anonymous function using func::std_target_t.
Notable, instance is holding the given unique uint64_t identifier to allow implementing the equality operator w/o RTTI, not supported by std::function.
| A | function arguments |
| func | free-function with A... arguments. |
Definition at line 1899 of file functional.hpp.