Delegated target function object, providing a fast path target function invocation.
More...
|
| ~delegate_t () noexcept |
|
constexpr size_t | cached_size () const noexcept |
|
template<typename T, std::enable_if_t< use_trivial_cache< T >(), bool > = true> |
constexpr const T * | data () const noexcept |
|
template<typename T, std::enable_if_t< use_any_heap< T >(), bool > = true> |
constexpr const T * | data () const noexcept |
|
template<typename T, std::enable_if_t< use_trivial_cache< T >(), bool > = true> |
constexpr T * | data () noexcept |
|
template<typename T, std::enable_if_t< use_any_heap< T >(), bool > = true> |
constexpr T * | data () noexcept |
|
| delegate_t (const delegate_t &o) noexcept |
|
| delegate_t (delegate_t &&o) noexcept |
|
constexpr size_t | heap_size () const noexcept |
|
constexpr bool | is_trivially_copyable () const noexcept |
| Returns true if the underlying target function is TriviallyCopyable .
|
|
constexpr R | operator() (A... args) const |
| Delegated fast path target function invocation, see above.
|
|
delegate_t & | operator= (const delegate_t &o) noexcept |
|
delegate_t & | operator= (delegate_t &&o) noexcept |
|
constexpr bool | operator== (const delegate_t< R, A... > &rhs) const noexcept |
| Delegated fast path target function equality operator.
|
|
constexpr size_t | target_size () const noexcept |
| Returns the size of underlying target function.
|
|
constexpr target_type | type () const noexcept |
| Return the func::target_type of this invocation function wrapper.
|
|
|
static delegate_type | delegate () noexcept |
|
static delegate_type | delegate (C1 *base, R(C0::*method)(A...), std::enable_if_t< std::is_base_of_v< C0, C1 >, bool >=true) noexcept |
| Construct a delegate_t<R, A...> instance from given this base-pointer and member-function.
|
|
static delegate_type | delegate (const I &data, R(*function)(I &, A...)) noexcept |
|
static delegate_type | delegate (I &&data, R(*function)(I &, A...)) noexcept |
|
static delegate_type | delegate (I *data_ptr, R(*function)(I *, A...)) noexcept |
|
static delegate_type | delegate (L function) noexcept |
|
static delegate_type | delegate (L function) noexcept |
|
static delegate_type | delegate (R(*function)(A...)) noexcept |
|
static delegate_type | delegate (uint64_t id, std::function< R(A...)> function) noexcept |
|
template<typename T, std::enable_if_t<!use_nontrivial_heap< T >(), bool > = true> |
static non_trivial_t * | getNonTrivialCtor () noexcept |
|
template<typename T, std::enable_if_t< use_nontrivial_heap< T >(), bool > = true> |
static non_trivial_t * | getNonTrivialCtor () noexcept |
|
static delegate_t | make (const target_func_t &tfunc) noexcept |
|
template<typename T, typename... P, std::enable_if_t< use_trivial_cache< T >(), bool > = true> |
static delegate_t | make (const target_func_t &tfunc, P... params) noexcept |
|
template<typename T, typename... P, std::enable_if_t< use_trivial_heap< T >(), bool > = true> |
static delegate_t | make (const target_func_t &tfunc, P... params) noexcept |
|
template<typename T, typename... P, std::enable_if_t< use_nontrivial_heap< T >(), bool > = true> |
static delegate_t | make (const target_func_t &tfunc, P... params) noexcept |
|
template<typename T> |
static constexpr bool | use_any_heap () |
|
template<typename T> |
static constexpr bool | use_nontrivial_heap () |
|
template<typename T> |
static constexpr bool | use_trivial_cache () |
|
template<typename T> |
static constexpr bool | use_trivial_heap () |
|
template<typename R, typename... A>
class jau::func::final_opt< R, A >
Delegated target function object, providing a fast path target function invocation.
func::std_target_t implementation for std::function instances, identifiable as func::target_type::std via jau::function<R(A...)>::type().
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().
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().
func::ylambda_target_t is a Y combinator and deducing this implementation for lambda closures usable for recursive algorithms.
func::lambda_target_t implementation for lambda closures, identifiable as func::target_type::lambda via jau::function<R(A...)>::type().
func::free_target_t implementation for free functions, identifiable as func::target_type::free via jau::function<R(A...)>::type().
func::member_target_t implementation for class member functions, identifiable as func::target_type::member via jau::function<R(A...)>::type().
func::null_target_t implementation for no function.
This static polymorphic target function delegate_t<R, A...> is contained by function<R(A...)> and completely holds up to 32 bytes sized TriviallyCopyable
target function objects to avoiding cache misses.
- contained within function<R(A...)> instance as a member
- avoiding need for dynamic polymorphism, i.e. heap allocated specialization referenced by base type
- using non-heap cache for up to 32 bytes sized
TriviallyCopyable
target function objects
- enhancing performance on most target function types by avoiding cache misses
- not using virtual function table indirection
- use static target-type
target_func_t
for callback- and equality-function, as well as for size
, type
and optional non_trivial_t
non_trivial_t
optionally holds constructor and destructor for non-trivial function data, a static target-type resource
- utilize constexpr inline for function invocation (callbacks)
- Template Parameters
-
R | function return type |
A | function arguments |
- See also
- Function Overview
identifiable as jau::func::target_type::null via jau::function<R(A...)>::type().
This special type is used for an empty jau::function instance w/o holding a function, e.g. when created with the default constructor.
- Template Parameters
-
R | function return type |
A | function arguments |
- See also
- Function Overview
- Template Parameters
-
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 |
- See also
- Function Overview
- Template Parameters
-
R | function return type |
A | function arguments |
- See also
- Function Overview
- Template Parameters
-
R | function return type |
L | typename holding the lambda closure |
A | function arguments |
- See also
- Function Overview
The Y combinator allows passing the unnamed lambda instance itself, enabling recursive invocation from within the lambda.
In other words, a this
reference of the unnamed lambda is passed to the lambda, similar to Deducing this
.
The ylambda function<R(A...)> is invoked w/o explicitly passing the object parameter, as it is implicitly passed down to the user's lambda implementation.
Example implementing a recursive lambda factorial function
function<int(
int)> f1 =
function<int(
int)>::bind_ylambda( [](
auto& self,
int x) ->
int {
if( 0 == x ) {
return 1;
} else {
return x * self(x-1);
}
} );
assert( 24 == f1(4) );
function<int(
int)> f2 = function<int(
int)>::bind_ylambda( [](function<
int(
int)>
::delegate_type& self,
int x) ->
int {
if( 0 == x ) {
return 1;
} else {
return x * self(x-1);
}
} );
assert( 24 == f2(4) );
delegate_t< R, A... > delegate_type
Class template jau::function is a general-purpose static-polymorphic function wrapper.
An instance is identifiable as func::target_type::ylambda via jau::function<R(A...)>::type().
- Template Parameters
-
R | function return type |
L | typename holding the lambda closure |
A | function arguments |
- See also
- Function Overview
-
Deducing this
-
Explicit object parameter
-
Curiously Recurring Template Pattern
- Template Parameters
-
R | function return type |
I | typename holding the captured data used by the function |
A | function arguments |
- See also
- Function Overview
Notable, instance is holding a unique uint64_t identifier to allow implementing the equality operator, not supported by std::function.
- Template Parameters
-
R | function return type |
A | function arguments |
- See also
- Function Overview
Definition at line 380 of file functional.hpp.