Skip to content

iox::cxx::function_ref< ReturnType(ArgTypes...)>🔗

cxx::function_ref is a non-owning reference to a callable. More...

#include <iceoryx_hoofs/cxx/function_ref.hpp>

Public Functions🔗

Name
function_ref()
Creates an empty function_ref in an invalid state.
~function_ref() =default
function_ref(const function_ref & ) =default
function_ref & operator=(const function_ref & ) =default
template <typename CallableType ,typename =std::enable_if_t<!is_function_pointer::value && !has_same_decayed_type::value && is_invocable::value>>
function_ref(CallableType && callable)
Creates a function_ref with a callable whose lifetime has to be longer than function_ref.
function_ref(ReturnType(*)(ArgTypes...) function)
Creates a function_ref from a function pointer.
function_ref(function_ref && rhs)
function_ref & operator=(function_ref && rhs)
ReturnType operator()(ArgTypes... args) const
Calls the provided callable.
operator bool() const
Checks whether a valid target is contained.
void swap(function_ref & rhs)
Swaps the contents of two function_ref's.

Detailed Description🔗

template <class ReturnType ,
class... ArgTypes>
class iox::cxx::function_ref< ReturnType(ArgTypes...)>;

cxx::function_ref is a non-owning reference to a callable.

Attention: Invoking an empty function_ref can lead to a program termination!

   It has these features:
    * No heap usage
    * No exceptions
    * Stateful lambda support
    * C++11/14 support
// Usage as function parameter
void fuu(cxx::function_ref<void()> callback)
{
    callback();
}
// Call the lambda
fuu([]{ doSomething(); });

// Usage with l-values
// Pitfall: Ensure that lifetime of callable suits the point in time of calling callback()
auto callable = [&]{ doSomething(); };
cxx::function_ref<void()> callback(callable);
// Call the callback
callback();

Public Functions Documentation🔗

function function_ref🔗

function_ref()

Creates an empty function_ref in an invalid state.

Note: Handle with care, program will terminate when calling an invalid function_ref

function ~function_ref🔗

~function_ref() =default

function function_ref🔗

function_ref(
    const function_ref & 
) =default

function operator=🔗

function_ref & operator=(
    const function_ref & 
) =default

function function_ref🔗

template <typename CallableType ,
typename  =std::enable_if_t<!is_function_pointer<CallableType>::value                                          && !has_same_decayed_type<CallableType, function_ref>::value                                          && is_invocable<CallableType, ArgTypes...>::value>>
function_ref(
    CallableType && callable
)

Creates a function_ref with a callable whose lifetime has to be longer than function_ref.

Parameters:

function function_ref🔗

function_ref(
    ReturnType(*)(ArgTypes...) function
)

Creates a function_ref from a function pointer.

Parameters:

  • function function pointer to function we want to reference

Note: This overload is needed, as the general implementation will not work properly for function pointers. This ctor is not needed anymore once we can use user-defined-deduction guides (C++17)

function function_ref🔗

function_ref(
    function_ref && rhs
)

function operator=🔗

function_ref & operator=(
    function_ref && rhs
)

function operator()🔗

ReturnType operator()(
    ArgTypes... args
) const

Calls the provided callable.

Parameters:

  • Arguments are forwarded to the underlying function pointer

Return: Returns the data type of the underlying function pointer

Attention: Invoking an empty function_ref can lead to a program termination!

function operator bool🔗

explicit operator bool() const

Checks whether a valid target is contained.

Return: True if valid target is contained, otherwise false

function swap🔗

void swap(
    function_ref & rhs
)

Swaps the contents of two function_ref's.

Parameters:


Updated on 18 December 2023 at 13:11:42 CET