iceoryx_doc  1.0.1
Public Member Functions | List of all members
iox::cxx::function_ref< ReturnType(ArgTypes...)> Class Template Reference

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

#include <function_ref.hpp>

Public Member Functions

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

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.

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

Constructor & Destructor Documentation

◆ function_ref() [1/2]

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

Creates an empty function_ref in an invalid state.

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

◆ function_ref() [2/2]

template<class ReturnType , class... ArgTypes>
template<typename CallableType , typename , typename >
iox::cxx::function_ref< ReturnType(ArgTypes...)>::function_ref ( CallableType &&  callable)
inlinenoexcept

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

Parameters
[in]callablethat is not a function_ref

Member Function Documentation

◆ operator bool()

template<class ReturnType , class... ArgTypes>
iox::cxx::function_ref< ReturnType(ArgTypes...)>::operator bool
inlineexplicitnoexcept

Checks whether a valid target is contained.

Returns
True if valid target is contained, otherwise false

◆ operator()()

template<class ReturnType , class... ArgTypes>
ReturnType iox::cxx::function_ref< ReturnType(ArgTypes...)>::operator() ( ArgTypes...  args) const
inlinenoexcept

Calls the provided callable.

Parameters
[in]Argumentsare forwarded to the underlying function pointer
Returns
Returns the data type of the underlying function pointer

◆ swap()

template<class ReturnType , class... ArgTypes>
void iox::cxx::function_ref< ReturnType(ArgTypes...)>::swap ( function_ref< ReturnType(ArgTypes...)> &  rhs)
inlinenoexcept

Swaps the contents of two function_ref's.

Parameters
[in]Referenceto another function_ref

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