Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Public Types | Public Member Functions | Static Public Member Functions | List of all members
jau::function< R(A...)> Class Template Referencefinal

Class template jau::function is a general-purpose static-polymorphic function wrapper. More...

#include <functional.hpp>

Collaboration diagram for jau::function< R(A...)>:

Public Types

typedef func::delegate_t< R, A... > delegate_type
 The delegated target function type, i.e. More...
 
typedef R result_type
 The target function return type R. More...
 
typedef R result_type
 The target function return type R. More...
 
typedef func::target_t< R, A... > target_type
 The target function type, i.e. More...
 

Public Member Functions

 function () noexcept
 Null function constructor. More...
 
 function () noexcept
 Null function constructor. More...
 
template<typename C0 , typename C1 >
 function (C1 *base, R(C0::*mfunc)(A...)) noexcept
 Member function constructor. More...
 
template<typename C0 , typename C1 >
 function (C1 *base, R(C0::*mfunc)(A...)) noexcept
 Member function constructor. More...
 
 function (const function &o) noexcept=default
 
 function (const function &o) noexcept=default
 
template<typename I >
 function (const I &data, R(*func)(I &, A...)) noexcept
 Capture by value (copy) function constructor. More...
 
template<typename I >
 function (const I &data, R(*func)(I &, A...)) noexcept
 Capture by value (copy) function constructor. More...
 
 function (delegate_type _delegate, int dummy) noexcept
 Internally used delegate_t<R(A...)> constructor. More...
 
 function (function &&o) noexcept=default
 
 function (function &&o) noexcept=default
 
template<typename I >
 function (I &&data, R(*func)(I &, A...)) noexcept
 Capture by value (move) function constructor. More...
 
template<typename I >
 function (I &&data, R(*func)(I &, A...)) noexcept
 Capture by value (move) function constructor. More...
 
template<typename I >
 function (I *data_ptr, R(*func)(I *, A...)) noexcept
 Capture by-reference function constructor. More...
 
template<typename I >
 function (I *data_ptr, R(*func)(I *, A...)) noexcept
 Capture by reference function constructor. More...
 
template<typename L , std::enable_if_t<!std::is_same_v< L, std::shared_ptr< delegate_type > > &&!std::is_pointer_v< L > &&!std::is_same_v< L, R(A...)> &&!std::is_same_v< L, function< R(A...)> >, bool > = true>
 function (L func) noexcept
 Lambda function constructor. More...
 
template<typename L , std::enable_if_t<!std::is_same_v< L, std::shared_ptr< target_type > > &&!std::is_pointer_v< L > &&!std::is_same_v< L, R(A...)> &&!std::is_same_v< L, function< R(A...)> >, bool > = true>
 function (L func) noexcept
 Lambda function constructor. More...
 
 function (R(*func)(A...)) noexcept
 Free function constructor. More...
 
 function (R(*func)(A...)) noexcept
 Free function constructor. More...
 
 function (std::nullptr_t) noexcept
 Null function constructor. More...
 
 function (std::nullptr_t) noexcept
 Null function constructor. More...
 
 function (std::shared_ptr< target_type > _funcPtr, size_t asize_) noexcept
 target_type constructor More...
 
 function (uint64_t id, std::function< R(A...)> func) noexcept
 std::function constructor More...
 
 function (uint64_t id, std::function< R(A...)> func) noexcept
 std::function constructor More...
 
constexpr bool is_null () const noexcept
 Returns true if this instance does not hold a callable target function, i.e. More...
 
constexpr bool is_null () const noexcept
 Returns true if this instance does not hold a callable target function, i.e. More...
 
constexpr bool is_target_trivially_copyable () const noexcept
 Returns true if the underlying target function is TriviallyCopyable. More...
 
constexpr operator bool () const noexcept
 Returns true if this instance holds a callable target function, i.e. More...
 
constexpr operator bool () const noexcept
 Returns true if this instance holds a callable target function, i.e. More...
 
constexpr bool operator!= (const function< R(A...)> &rhs) const noexcept
 
constexpr bool operator!= (const function< R(A...)> &rhs) const noexcept
 
constexpr R operator() (A... args)
 
constexpr R operator() (A... args)
 
constexpr R operator() (A... args) const
 
constexpr R operator() (A... args) const
 
functionoperator= (const function &o) noexcept=default
 
functionoperator= (const function &o) noexcept=default
 
functionoperator= (function &&o) noexcept=default
 
functionoperator= (function &&o) noexcept=default
 
constexpr bool operator== (const function< R(A...)> &rhs) const noexcept
 
constexpr bool operator== (const function< R(A...)> &rhs) const noexcept
 
jau::type_info signature () const noexcept
 Returns signature of this function prototype R(A...) w/o underlying target function object. More...
 
jau::type_info signature () const noexcept
 Returns signature of this function prototype R(A...) w/o underlying target function details. More...
 
constexpr size_t size () const noexcept
 Return the total size of this instance, may include heap allocated by delegate for bigger target functions. More...
 
constexpr size_t target_size () const noexcept
 Returns the size of underlying target function. More...
 
constexpr size_t target_size () const noexcept
 Returns the size of the target type
More...
 
std::string toString () const
 Return a string representation of this instance. More...
 
std::string toString () const
 
constexpr func::target_type type () const noexcept
 Return the jau::func::type of this instance. More...
 
constexpr func::target_type type () const noexcept
 Return the jau::func::type of this instance. More...
 

Static Public Member Functions

template<typename L >
static function< R(A...)> bind_lambda (L func) noexcept
 Lambda function bind factory. More...
 
template<typename L >
static function< R(A...)> bind_ylambda (L func) noexcept
 Y combinator Lambda function bind factory. More...
 

Detailed Description

template<typename R, typename... A>
class jau::function< R(A...)>

Class template jau::function is a general-purpose static-polymorphic function wrapper.

Class template jau::function is a general-purpose polymorphic function wrapper.

See Function Overview.

Template Parameters
Rfunction return type
Afunction arguments
See also
Function Overview
Function Usage

Definition at line 1224 of file functional.hpp.

Member Typedef Documentation

◆ delegate_type

template<typename R , typename... A>
typedef func::delegate_t<R, A...> jau::function< R(A...)>::delegate_type

The delegated target function type, i.e.

func::delegate_t<R, A...>

Definition at line 1227 of file functional.hpp.

◆ result_type [1/2]

template<typename R , typename... A>
typedef R jau::function< R(A...)>::result_type

The target function return type R.

Definition at line 1234 of file functional.hpp.

◆ target_type

template<typename R , typename... A>
typedef func::target_t<R, A...> jau::function< R(A...)>::target_type

The target function type, i.e.

func::target_t<R, A...>

Definition at line 619 of file functional2.hpp.

◆ result_type [2/2]

template<typename R , typename... A>
typedef R jau::function< R(A...)>::result_type

The target function return type R.

Definition at line 627 of file functional2.hpp.

Constructor & Destructor Documentation

◆ function() [1/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( )
inlinenoexcept

Null function constructor.

Constructs an instance with a null target function.

See also
function Overview
function Usage

Definition at line 1244 of file functional.hpp.

◆ function() [2/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( std::nullptr_t  )
inlinenoexcept

Null function constructor.

Constructs an instance with a null target function.

See also
function Overview
function Usage

Definition at line 1256 of file functional.hpp.

◆ function() [3/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( delegate_type  _delegate,
int  dummy 
)
inlineexplicitnoexcept

Internally used delegate_t<R(A...)> constructor.

May utilize copy elision and/or named return value optimization (NRVO).

See also
function Overview
function Usage

Definition at line 1269 of file functional.hpp.

◆ function() [4/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( R(*)(A...)  func)
inlinenoexcept

Free function constructor.

Constructs an instance by taking a free target function, which may also be a non-capturing lambda if explicitly bind_free().

See also
function Overview
function Usage

Definition at line 1281 of file functional.hpp.

◆ function() [5/24]

template<typename R , typename... A>
template<typename L , std::enable_if_t<!std::is_same_v< L, std::shared_ptr< delegate_type > > &&!std::is_pointer_v< L > &&!std::is_same_v< L, R(A...)> &&!std::is_same_v< L, function< R(A...)> >, bool > = true>
jau::function< R(A...)>::function ( func)
inlinenoexcept

Lambda function constructor.

Constructs an instance by taking a lambda function.

Template Parameters
Ltypename holding the lambda closure
Parameters
functhe lambda reference
See also
function Overview
function Usage

Definition at line 1302 of file functional.hpp.

◆ function() [6/24]

template<typename R , typename... A>
template<typename C0 , typename C1 >
jau::function< R(A...)>::function ( C1 base,
R(C0::*)(A...)  mfunc 
)
inlinenoexcept

Member function constructor.

Constructs an instance by taking a member target function.

Template Parameters
C0class type holding the member-function
C1class derived from C0 or C0 of this base-pointer used to invoke the member-function
Parameters
basepointer to the class instance of the member function
mfuncmember function of class
See also
function Overview
function Usage

Definition at line 1357 of file functional.hpp.

◆ function() [7/24]

template<typename R , typename... A>
template<typename I >
jau::function< R(A...)>::function ( const I &  data,
R(*)(I &, A...)  func 
)
inlinenoexcept

Capture by value (copy) function constructor.

Constructs an instance 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.

Template Parameters
Itypename holding the captured data used by the function
Parameters
datadata type instance holding the captured data
funcfunction with R return value and A... arguments.
See also
function Overview
function Usage

Definition at line 1379 of file functional.hpp.

◆ function() [8/24]

template<typename R , typename... A>
template<typename I >
jau::function< R(A...)>::function ( I &&  data,
R(*)(I &, A...)  func 
)
inlinenoexcept

Capture by value (move) function constructor.

Constructs an instance 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.

Template Parameters
Itypename holding the captured data used by the function
Parameters
datadata type instance holding the captured data
funcfunction with R return value and A... arguments.
See also
function Overview
function Usage

Definition at line 1401 of file functional.hpp.

◆ function() [9/24]

template<typename R , typename... A>
template<typename I >
jau::function< R(A...)>::function ( I *  data_ptr,
R(*)(I *, A...)  func 
)
inlinenoexcept

Capture by-reference function constructor.

Constructs an instance 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.

Template Parameters
Itypename holding the captured data used by the function
Parameters
data_ptrdata type reference to instance holding the captured data
funcfunction with R return value and A... arguments.
See also
function Overview
function Usage

Definition at line 1421 of file functional.hpp.

◆ function() [10/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( uint64_t  id,
std::function< R(A...)>  func 
)
inlinenoexcept

std::function constructor

Constructs an instance by copying the 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.

Parameters
funcfree-function with R return value and A... arguments.
See also
function Overview
function Usage

Definition at line 1439 of file functional.hpp.

◆ function() [11/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( const function< R(A...)> &  o)
defaultnoexcept

◆ function() [12/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( function< R(A...)> &&  o)
defaultnoexcept

◆ function() [13/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( )
inlinenoexcept

Null function constructor.

Constructs an instance with a null target function.

See also
function Overview
function Usage

Definition at line 637 of file functional2.hpp.

◆ function() [14/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( std::nullptr_t  )
inlinenoexcept

Null function constructor.

Constructs an instance with a null target function.

See also
function Overview
function Usage

Definition at line 650 of file functional2.hpp.

◆ function() [15/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( std::shared_ptr< target_type _funcPtr,
size_t  asize_ 
)
inlineexplicitnoexcept

target_type constructor

Constructs an instance with the given shared target function pointer.

See also
function Overview
function Usage

Definition at line 663 of file functional2.hpp.

◆ function() [16/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( R(*)(A...)  func)
inlinenoexcept

Free function constructor.

Constructs an instance by taking a free target function, which may also be a non-capturing lambda if explicitly bind_free().

See also
function Overview
function Usage

Definition at line 676 of file functional2.hpp.

◆ function() [17/24]

template<typename R , typename... A>
template<typename L , std::enable_if_t<!std::is_same_v< L, std::shared_ptr< target_type > > &&!std::is_pointer_v< L > &&!std::is_same_v< L, R(A...)> &&!std::is_same_v< L, function< R(A...)> >, bool > = true>
jau::function< R(A...)>::function ( func)
inlinenoexcept

Lambda function constructor.

Constructs an instance by taking a lambda function.

Template Parameters
Ltypename holding the lambda closure
Parameters
functhe lambda reference
See also
function Overview
function Usage

Definition at line 697 of file functional2.hpp.

◆ function() [18/24]

template<typename R , typename... A>
template<typename C0 , typename C1 >
jau::function< R(A...)>::function ( C1 base,
R(C0::*)(A...)  mfunc 
)
inlinenoexcept

Member function constructor.

Constructs an instance by taking a member target function.

Template Parameters
C0class type holding the member-function
C1class derived from C0 or C0 of this base-pointer used to invoke the member-function
Parameters
basepointer to the class instance of the member function
mfuncmember function of class
See also
function Overview
function Usage

Definition at line 715 of file functional2.hpp.

◆ function() [19/24]

template<typename R , typename... A>
template<typename I >
jau::function< R(A...)>::function ( const I &  data,
R(*)(I &, A...)  func 
)
inlinenoexcept

Capture by value (copy) function constructor.

Constructs an instance 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.

Template Parameters
Itypename holding the captured data used by the function
Parameters
datadata type instance holding the captured data
funcfunction with R return value and A... arguments.
See also
function Overview
function Usage

Definition at line 738 of file functional2.hpp.

◆ function() [20/24]

template<typename R , typename... A>
template<typename I >
jau::function< R(A...)>::function ( I &&  data,
R(*)(I &, A...)  func 
)
inlinenoexcept

Capture by value (move) function constructor.

Constructs an instance 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.

Template Parameters
Itypename holding the captured data used by the function
Parameters
datadata type instance holding the captured data
funcfunction with R return value and A... arguments.
See also
function Overview
function Usage

Definition at line 761 of file functional2.hpp.

◆ function() [21/24]

template<typename R , typename... A>
template<typename I >
jau::function< R(A...)>::function ( I *  data_ptr,
R(*)(I *, A...)  func 
)
inlinenoexcept

Capture by reference function constructor.

Constructs an instance 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.

Template Parameters
Itypename holding the captured data used by the function
Parameters
data_ptrdata type reference to instance holding the captured data
funcfunction with R return value and A... arguments.
See also
function Overview
function Usage

Definition at line 782 of file functional2.hpp.

◆ function() [22/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( uint64_t  id,
std::function< R(A...)>  func 
)
inlinenoexcept

std::function constructor

Constructs an instance by copying the 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.

Parameters
funcfree-function with R return value and A... arguments.
See also
function Overview
function Usage

Definition at line 801 of file functional2.hpp.

◆ function() [23/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( const function< R(A...)> &  o)
defaultnoexcept

◆ function() [24/24]

template<typename R , typename... A>
jau::function< R(A...)>::function ( function< R(A...)> &&  o)
defaultnoexcept

Member Function Documentation

◆ bind_lambda()

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

Lambda function bind factory.

Constructs an instance by taking a lambda function.

Template Parameters
Ltypename holding the lambda closure
Parameters
functhe lambda reference
See also
function Overview
function Usage

Definition at line 1318 of file functional.hpp.

◆ bind_ylambda()

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

Y combinator Lambda function bind factory.

Constructs an instance by taking a lambda function, implementing a Y combinator and deducing this lambda closure, see ylambda_target_t.

Template Parameters
Ltypename holding the lambda closure
Parameters
functhe lambda reference
See also
ylambda_target_t
function Overview
function Usage

Definition at line 1339 of file functional.hpp.

◆ operator=() [1/4]

template<typename R , typename... A>
function & jau::function< R(A...)>::operator= ( const function< R(A...)> &  o)
defaultnoexcept

◆ operator=() [2/4]

template<typename R , typename... A>
function & jau::function< R(A...)>::operator= ( function< R(A...)> &&  o)
defaultnoexcept

◆ type() [1/2]

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

Return the jau::func::type of this instance.

Definition at line 1449 of file functional.hpp.

◆ is_null() [1/2]

template<typename R , typename... A>
constexpr bool jau::function< R(A...)>::is_null ( ) const
inlineconstexprnoexcept

Returns true if this instance does not hold a callable target function, i.e.

is of func::target_type::null.

Definition at line 1452 of file functional.hpp.

◆ operator bool() [1/2]

template<typename R , typename... A>
constexpr jau::function< R(A...)>::operator bool ( ) const
inlineexplicitconstexprnoexcept

Returns true if this instance holds a callable target function, i.e.

is not of func::target_type::null.

Definition at line 1455 of file functional.hpp.

◆ signature() [1/2]

template<typename R , typename... A>
jau::type_info jau::function< R(A...)>::signature ( ) const
inlinenoexcept

Returns signature of this function prototype R(A...) w/o underlying target function object.

Definition at line 1458 of file functional.hpp.

◆ is_target_trivially_copyable()

template<typename R , typename... A>
constexpr bool jau::function< R(A...)>::is_target_trivially_copyable ( ) const
inlineconstexprnoexcept

Returns true if the underlying target function is TriviallyCopyable.

Definition at line 1463 of file functional.hpp.

◆ size()

template<typename R , typename... A>
constexpr size_t jau::function< R(A...)>::size ( ) const
inlineconstexprnoexcept

Return the total size of this instance, may include heap allocated by delegate for bigger target functions.

Definition at line 1466 of file functional.hpp.

◆ target_size() [1/2]

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

Returns the size of underlying target function.

Definition at line 1469 of file functional.hpp.

◆ toString() [1/2]

template<typename R , typename... A>
std::string jau::function< R(A...)>::toString ( ) const
inline

Return a string representation of this instance.

The string representation contains the complete signature and detailed memory footprint.

Definition at line 1475 of file functional.hpp.

◆ operator()() [1/4]

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

Definition at line 1484 of file functional.hpp.

◆ operator()() [2/4]

template<typename R , typename... A>
constexpr R jau::function< R(A...)>::operator() ( A...  args)
inlineconstexpr

Definition at line 1487 of file functional.hpp.

◆ operator==() [1/2]

template<typename R , typename... A>
constexpr bool jau::function< R(A...)>::operator== ( const function< R(A...)> &  rhs) const
inlineconstexprnoexcept

Definition at line 1491 of file functional.hpp.

◆ operator!=() [1/2]

template<typename R , typename... A>
constexpr bool jau::function< R(A...)>::operator!= ( const function< R(A...)> &  rhs) const
inlineconstexprnoexcept

Definition at line 1494 of file functional.hpp.

◆ operator=() [3/4]

template<typename R , typename... A>
function & jau::function< R(A...)>::operator= ( const function< R(A...)> &  o)
defaultnoexcept

◆ operator=() [4/4]

template<typename R , typename... A>
function & jau::function< R(A...)>::operator= ( function< R(A...)> &&  o)
defaultnoexcept

◆ type() [2/2]

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

Return the jau::func::type of this instance.

Definition at line 812 of file functional2.hpp.

◆ is_null() [2/2]

template<typename R , typename... A>
constexpr bool jau::function< R(A...)>::is_null ( ) const
inlineconstexprnoexcept

Returns true if this instance does not hold a callable target function, i.e.

is of func::target_type::null.

Definition at line 815 of file functional2.hpp.

◆ operator bool() [2/2]

template<typename R , typename... A>
constexpr jau::function< R(A...)>::operator bool ( ) const
inlineexplicitconstexprnoexcept

Returns true if this instance holds a callable target function, i.e.

is not of func::target_type::null.

Definition at line 818 of file functional2.hpp.

◆ signature() [2/2]

template<typename R , typename... A>
jau::type_info jau::function< R(A...)>::signature ( ) const
inlinenoexcept

Returns signature of this function prototype R(A...) w/o underlying target function details.

Definition at line 821 of file functional2.hpp.

◆ target_size() [2/2]

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

Returns the size of the target type

Definition at line 826 of file functional2.hpp.

◆ toString() [2/2]

template<typename R , typename... A>
std::string jau::function< R(A...)>::toString ( ) const
inline

Definition at line 828 of file functional2.hpp.

◆ operator()() [3/4]

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

Definition at line 836 of file functional2.hpp.

◆ operator()() [4/4]

template<typename R , typename... A>
constexpr R jau::function< R(A...)>::operator() ( A...  args)
inlineconstexpr

Definition at line 839 of file functional2.hpp.

◆ operator==() [2/2]

template<typename R , typename... A>
constexpr bool jau::function< R(A...)>::operator== ( const function< R(A...)> &  rhs) const
inlineconstexprnoexcept

Definition at line 843 of file functional2.hpp.

◆ operator!=() [2/2]

template<typename R , typename... A>
constexpr bool jau::function< R(A...)>::operator!= ( const function< R(A...)> &  rhs) const
inlineconstexprnoexcept

Definition at line 846 of file functional2.hpp.


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