jaulib v1.3.6
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
jau::func::final_opt< R, A > Class Template Reference

Delegated target function object, providing a fast path target function invocation. More...

#include <functional.hpp>

Collaboration diagram for jau::func::final_opt< R, A >:

Classes

struct  final_opt
 C++ conform Pointer to Member Function (PMF) More...
 

Public Types

typedef delegate_t< R, A... > delegate_type
 
typedef delegate_t< R, A... > delegate_type
 
typedef delegate_t< R, A... > delegate_type
 
typedef delegate_t< R, A... > delegate_type
 
typedef delegate_t< R, A... > delegate_type
 
typedef delegate_t< R, A... > delegate_type
 
typedef delegate_t< R, A... > delegate_type
 
typedef delegate_t< R, A... > delegate_type
 
typedef jau::nsize_t size_type
 Utilize a natural size type jau::nsize_t.
 

Public Member Functions

 ~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 Public Member Functions

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 ()
 

Detailed Description

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
Rfunction return type
Afunction 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
Rfunction return type
Afunction arguments
See also
Function Overview
Template Parameters
Rfunction return type
C0class type holding the member-function
C1class derived from C0 or C0 of this base-pointer used to invoke the member-function
Afunction arguments
See also
Function Overview
Template Parameters
Rfunction return type
Afunction arguments
See also
Function Overview
Template Parameters
Rfunction return type
Ltypename holding the lambda closure
Afunction 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); // recursion, calling itself w/o explicitly passing `self`
}
} );
assert( 24 == f1(4) ); // `self` is bound to delegate<R(A...)> `f.target`, `x` is 4
// or using explicit function<R(A...)>::delegate_type
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); // recursion, calling itself w/o explicitly passing `self`
}
} );
assert( 24 == f2(4) ); // `self` is bound to function<int(int)>::delegate_type `f.target`, `x` is 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
Rfunction return type
Ltypename holding the lambda closure
Afunction arguments
See also
Function Overview
Deducing this
Explicit object parameter
Curiously Recurring Template Pattern
Template Parameters
Rfunction return type
Itypename holding the captured data used by the function
Afunction 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
Rfunction return type
Afunction arguments
See also
Function Overview

Definition at line 380 of file functional.hpp.

Member Typedef Documentation

◆ size_type

template<typename R, typename... A>
typedef jau::nsize_t jau::func::final_opt< R, A >::size_type

Utilize a natural size type jau::nsize_t.

Definition at line 383 of file functional.hpp.

◆ delegate_type [1/8]

template<typename R, typename... A>
typedef delegate_t<R, A...> jau::func::final_opt< R, A >::delegate_type

Definition at line 724 of file functional.hpp.

◆ delegate_type [2/8]

template<typename R, typename... A>
typedef delegate_t<R, A...> jau::func::final_opt< R, A >::delegate_type

Definition at line 762 of file functional.hpp.

◆ delegate_type [3/8]

template<typename R, typename... A>
typedef delegate_t<R, A...> jau::func::final_opt< R, A >::delegate_type

Definition at line 869 of file functional.hpp.

◆ delegate_type [4/8]

template<typename R, typename... A>
typedef delegate_t<R, A...> jau::func::final_opt< R, A >::delegate_type

Definition at line 917 of file functional.hpp.

◆ delegate_type [5/8]

template<typename R, typename... A>
typedef delegate_t<R, A...> jau::func::final_opt< R, A >::delegate_type

Definition at line 1007 of file functional.hpp.

◆ delegate_type [6/8]

template<typename R, typename... A>
typedef delegate_t<R, A...> jau::func::final_opt< R, A >::delegate_type

Definition at line 1065 of file functional.hpp.

◆ delegate_type [7/8]

template<typename R, typename... A>
typedef delegate_t<R, A...> jau::func::final_opt< R, A >::delegate_type

Definition at line 1123 of file functional.hpp.

◆ delegate_type [8/8]

template<typename R, typename... A>
typedef delegate_t<R, A...> jau::func::final_opt< R, A >::delegate_type

Definition at line 1177 of file functional.hpp.

Constructor & Destructor Documentation

◆ ~delegate_t()

template<typename R, typename... A>
jau::func::final_opt< R, A >::~delegate_t ( )
inlinenoexcept

Definition at line 539 of file functional.hpp.

Member Function Documentation

◆ use_trivial_cache()

template<typename R, typename... A>
template<typename T>
static constexpr bool jau::func::final_opt< R, A >::use_trivial_cache ( )
inlinestaticconstexpr

Definition at line 386 of file functional.hpp.

◆ use_trivial_heap()

template<typename R, typename... A>
template<typename T>
static constexpr bool jau::func::final_opt< R, A >::use_trivial_heap ( )
inlinestaticconstexpr

Definition at line 391 of file functional.hpp.

◆ use_any_heap()

template<typename R, typename... A>
template<typename T>
static constexpr bool jau::func::final_opt< R, A >::use_any_heap ( )
inlinestaticconstexpr

Definition at line 396 of file functional.hpp.

◆ use_nontrivial_heap()

template<typename R, typename... A>
template<typename T>
static constexpr bool jau::func::final_opt< R, A >::use_nontrivial_heap ( )
inlinestaticconstexpr

Definition at line 401 of file functional.hpp.

◆ make() [1/4]

template<typename R, typename... A>
static delegate_t jau::func::final_opt< R, A >::make ( const target_func_t & tfunc)
inlinestaticnoexcept

Definition at line 474 of file functional.hpp.

Here is the caller graph for this function:

◆ make() [2/4]

template<typename R, typename... A>
template<typename T, typename... P, std::enable_if_t< use_trivial_cache< T >(), bool > = true>
static delegate_t jau::func::final_opt< R, A >::make ( const target_func_t & tfunc,
P... params )
inlinestaticnoexcept

Definition at line 482 of file functional.hpp.

◆ make() [3/4]

template<typename R, typename... A>
template<typename T, typename... P, std::enable_if_t< use_trivial_heap< T >(), bool > = true>
static delegate_t jau::func::final_opt< R, A >::make ( const target_func_t & tfunc,
P... params )
inlinestaticnoexcept

Definition at line 492 of file functional.hpp.

◆ make() [4/4]

template<typename R, typename... A>
template<typename T, typename... P, std::enable_if_t< use_nontrivial_heap< T >(), bool > = true>
static delegate_t jau::func::final_opt< R, A >::make ( const target_func_t & tfunc,
P... params )
inlinestaticnoexcept

Definition at line 502 of file functional.hpp.

◆ getNonTrivialCtor() [1/2]

template<typename R, typename... A>
template<typename T, std::enable_if_t<!use_nontrivial_heap< T >(), bool > = true>
static non_trivial_t * jau::func::final_opt< R, A >::getNonTrivialCtor ( )
inlinestaticnoexcept

Definition at line 512 of file functional.hpp.

◆ getNonTrivialCtor() [2/2]

template<typename R, typename... A>
template<typename T, std::enable_if_t< use_nontrivial_heap< T >(), bool > = true>
static non_trivial_t * jau::func::final_opt< R, A >::getNonTrivialCtor ( )
inlinestaticnoexcept

Definition at line 517 of file functional.hpp.

◆ delegate_t() [1/2]

template<typename R, typename... A>
jau::func::final_opt< R, A >::delegate_t ( const delegate_t & o)
inlinenoexcept

Definition at line 541 of file functional.hpp.

◆ delegate_t() [2/2]

template<typename R, typename... A>
jau::func::final_opt< R, A >::delegate_t ( delegate_t && o)
inlinenoexcept

Definition at line 560 of file functional.hpp.

◆ operator=() [1/2]

template<typename R, typename... A>
delegate_t & jau::func::final_opt< R, A >::operator= ( const delegate_t & o)
inlinenoexcept

Definition at line 582 of file functional.hpp.

◆ operator=() [2/2]

template<typename R, typename... A>
delegate_t & jau::func::final_opt< R, A >::operator= ( delegate_t && o)
inlinenoexcept

Definition at line 627 of file functional.hpp.

◆ data() [1/4]

template<typename R, typename... A>
template<typename T, std::enable_if_t< use_trivial_cache< T >(), bool > = true>
const T * jau::func::final_opt< R, A >::data ( ) const
inlineconstexprnoexcept

Definition at line 657 of file functional.hpp.

Here is the caller graph for this function:

◆ data() [2/4]

template<typename R, typename... A>
template<typename T, std::enable_if_t< use_trivial_cache< T >(), bool > = true>
T * jau::func::final_opt< R, A >::data ( )
inlineconstexprnoexcept

Definition at line 662 of file functional.hpp.

◆ data() [3/4]

template<typename R, typename... A>
template<typename T, std::enable_if_t< use_any_heap< T >(), bool > = true>
const T * jau::func::final_opt< R, A >::data ( ) const
inlineconstexprnoexcept

Definition at line 668 of file functional.hpp.

◆ data() [4/4]

template<typename R, typename... A>
template<typename T, std::enable_if_t< use_any_heap< T >(), bool > = true>
T * jau::func::final_opt< R, A >::data ( )
inlineconstexprnoexcept

Definition at line 673 of file functional.hpp.

◆ operator()()

template<typename R, typename... A>
R jau::func::final_opt< R, A >::operator() ( A... args) const
inlineconstexpr

Delegated fast path target function invocation, see above.

Parameters
argstarget function arguments
Returns
target function result

Definition at line 683 of file functional.hpp.

◆ operator==()

template<typename R, typename... A>
bool jau::func::final_opt< R, A >::operator== ( const delegate_t< R, A... > & rhs) const
inlineconstexprnoexcept

Delegated fast path target function equality operator.

Parameters
rhs
Returns

Definition at line 693 of file functional.hpp.

◆ is_trivially_copyable()

template<typename R, typename... A>
bool jau::func::final_opt< R, A >::is_trivially_copyable ( ) const
inlineconstexprnoexcept

Returns true if the underlying target function is TriviallyCopyable.

Definition at line 698 of file functional.hpp.

◆ heap_size()

template<typename R, typename... A>
size_t jau::func::final_opt< R, A >::heap_size ( ) const
inlineconstexprnoexcept

Definition at line 700 of file functional.hpp.

◆ cached_size()

template<typename R, typename... A>
size_t jau::func::final_opt< R, A >::cached_size ( ) const
inlineconstexprnoexcept

Definition at line 701 of file functional.hpp.

◆ target_size()

template<typename R, typename... A>
size_t jau::func::final_opt< R, A >::target_size ( ) const
inlineconstexprnoexcept

Returns the size of underlying target function.

Definition at line 704 of file functional.hpp.

◆ type()

template<typename R, typename... A>
target_type jau::func::final_opt< R, A >::type ( ) const
inlineconstexprnoexcept

Return the func::target_type of this invocation function wrapper.

Definition at line 707 of file functional.hpp.

◆ delegate() [1/9]

template<typename R, typename... A>
static delegate_type jau::func::final_opt< R, A >::delegate ( )
inlinestaticnoexcept

Definition at line 744 of file functional.hpp.

◆ delegate() [2/9]

template<typename R, typename... A>
static delegate_type jau::func::final_opt< R, A >::delegate ( C1 * base,
R(C0::* method )(A...),
std::enable_if_t< std::is_base_of_v< C0, C1 >, bool > = true )
inlinestaticnoexcept

Construct a delegate_t<R, A...> instance from given this base-pointer and member-function.

This factory function is only enabled if C0 is base of C1.

Parameters
basethis base-pointer of class C1 derived from C0 or C0 used to invoke the member-function
methodmember-function of class C0
Returns
delegate_t<R, A...> instance holding the target-function object.

Definition at line 851 of file functional.hpp.

◆ delegate() [3/9]

template<typename R, typename... A>
static delegate_type jau::func::final_opt< R, A >::delegate ( R(* function )(A...))
inlinestaticnoexcept

Definition at line 900 of file functional.hpp.

◆ delegate() [4/9]

template<typename R, typename... A>
static delegate_type jau::func::final_opt< R, A >::delegate ( L function)
inlinestaticnoexcept

Definition at line 953 of file functional.hpp.

◆ delegate() [5/9]

template<typename R, typename... A>
static delegate_type jau::func::final_opt< R, A >::delegate ( L function)
inlinestaticnoexcept

Definition at line 1048 of file functional.hpp.

◆ delegate() [6/9]

template<typename R, typename... A>
static delegate_type jau::func::final_opt< R, A >::delegate ( const I & data,
R(* function )(I &, A...) )
inlinestaticnoexcept

Definition at line 1102 of file functional.hpp.

◆ delegate() [7/9]

template<typename R, typename... A>
static delegate_type jau::func::final_opt< R, A >::delegate ( I && data,
R(* function )(I &, A...) )
inlinestaticnoexcept

Definition at line 1106 of file functional.hpp.

◆ delegate() [8/9]

template<typename R, typename... A>
static delegate_type jau::func::final_opt< R, A >::delegate ( I * data_ptr,
R(* function )(I *, A...) )
inlinestaticnoexcept

Definition at line 1158 of file functional.hpp.

◆ delegate() [9/9]

template<typename R, typename... A>
static delegate_type jau::func::final_opt< R, A >::delegate ( uint64_t id,
std::function< R(A...)> function )
inlinestaticnoexcept

Definition at line 1217 of file functional.hpp.


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