CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Loading...
Searching...
No Matches
FunctionWrapper< R(Args...)> Class Template Reference

A non-owning type-erased reference to a callable object. More...

#include <function_wrapper.hh>

Public Member Functions

 FunctionWrapper (FunctionWrapper &)=default
 This is a non-owning reference, its copy constructor is safe to use for passing down the stack.
 FunctionWrapper (FunctionWrapper &&)=delete
FunctionWrapperoperator= (FunctionWrapper &&)=delete
template<typename T>
requires (!std::is_same_v<T, FunctionWrapper>)
 FunctionWrapper (T &&fn)
 Construct the type-erased function wrapper, capturing the lambda.
operator() (Args... args)
 Invoke the captured lambda.

Detailed Description

template<class R, class... Args>
class FunctionWrapper< R(Args...)>

A non-owning type-erased reference to a callable object.

This is used to pass lambdas (and similar) down the stack without increasing code size by template specialisation. Instances of this class must not be stored, they should be used only for passing type-erased callable objects down the stack.

Instances of this class are two words: a reference to the lambda, and a wrapper callback that invokes the lambda.

This is similar to std::function but is non-owning and so is guaranteed not to allocate memory (the called function may capture memory).

Definition at line 25 of file function_wrapper.hh.

Constructor & Destructor Documentation

◆ FunctionWrapper()

template<class R, class... Args>
template<typename T>
requires (!std::is_same_v<T, FunctionWrapper>)
FunctionWrapper< R(Args...)>::FunctionWrapper ( T && fn)
inline

Construct the type-erased function wrapper, capturing the lambda.

Definition at line 94 of file function_wrapper.hh.

Member Function Documentation

◆ operator()()

template<class R, class... Args>
R FunctionWrapper< R(Args...)>::operator() ( Args... args)
inline

Invoke the captured lambda.

Definition at line 106 of file function_wrapper.hh.


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