iox::cxx::function_ref< ReturnType(ArgTypes...)>🔗
cxx::function_ref is a non-owning reference to a callable. More...
#include <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_ref |
function_ref(CallableType && callable) Creates a function_ref with a callable whose lifetime has to be longer than function_ref. |
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.
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🔗
inline 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_ref<std::remove_reference_t<CallableType>>::value>,
typename =std::enable_if_t<is_invocable<CallableType, ArgTypes...>::value>>
inline function_ref(
CallableType && callable
)
Creates a function_ref with a callable whose lifetime has to be longer than function_ref.
Parameters:
- callable that is not a function_ref
function function_ref🔗
inline function_ref(
function_ref && rhs
)
function operator=🔗
function_ref & operator=(
function_ref && rhs
)
function operator()🔗
inline 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
function operator bool🔗
inline explicit operator bool() const
Checks whether a valid target is contained.
Return: True if valid target is contained, otherwise false
function swap🔗
inline void swap(
function_ref & rhs
)
Swaps the contents of two function_ref's.
Parameters:
- Reference to another function_ref
Updated on 26 April 2021 at 15:31:01 CEST