Gaia-ECS v1.0.0
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::util::SmallFunc Class Reference

Move-only function wrapper with inline storage for small callables. Callables too large for the inline buffer use SmallBlockAllocator when GAIA_FUNC_WRAPPER_SMALLBLOCK is enabled. More...

#include <small_func.h>

Public Member Functions

 ~SmallFunc ()
 Destroys the stored callable, if any.
 
 SmallFunc (const SmallFunc &)=delete
 
SmallFuncoperator= (const SmallFunc &)=delete
 
 SmallFunc (SmallFunc &&other) noexcept
 Move-constructs the wrapper.
 
SmallFuncoperator= (SmallFunc &&other) noexcept
 Move-assigns the wrapper.
 
template<typename F , typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, SmallFunc>>>
 SmallFunc (F &&f)
 Constructs a wrapper from a callable compatible with void().
 
template<typename F , typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, SmallFunc>>>
SmallFuncoperator= (F &&f)
 Replaces the stored callable.
 
void exec ()
 Executes the stored callable.
 
void operator() ()
 Executes the stored callable.
 
void reset ()
 Clears the wrapper.
 
 operator bool () const
 Returns true when a callable is stored.
 

Static Public Member Functions

template<typename F >
static SmallFunc create (F &&f)
 Creates a wrapper from a callable compatible with void().
 
static void destroy (SmallFunc &func)
 Destroys the callable held by the wrapper.
 

Detailed Description

Move-only function wrapper with inline storage for small callables. Callables too large for the inline buffer use SmallBlockAllocator when GAIA_FUNC_WRAPPER_SMALLBLOCK is enabled.

Constructor & Destructor Documentation

◆ SmallFunc() [1/2]

gaia::util::SmallFunc::SmallFunc ( SmallFunc &&  other)
inlinenoexcept

Move-constructs the wrapper.

Parameters
otherSource wrapper.

◆ SmallFunc() [2/2]

template<typename F , typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, SmallFunc>>>
gaia::util::SmallFunc::SmallFunc ( F &&  f)
inline

Constructs a wrapper from a callable compatible with void().

Template Parameters
FCallable type.
Parameters
fCallable object.

Member Function Documentation

◆ create()

template<typename F >
static SmallFunc gaia::util::SmallFunc::create ( F &&  f)
inlinestatic

Creates a wrapper from a callable compatible with void().

Template Parameters
FCallable type.
Parameters
fCallable object.
Returns
New function wrapper.

◆ destroy()

static void gaia::util::SmallFunc::destroy ( SmallFunc func)
inlinestatic

Destroys the callable held by the wrapper.

Parameters
funcWrapper to clear.

◆ operator=() [1/2]

template<typename F , typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, SmallFunc>>>
SmallFunc & gaia::util::SmallFunc::operator= ( F &&  f)
inline

Replaces the stored callable.

Template Parameters
FCallable type.
Parameters
fCallable object.
Returns
Reference to this wrapper.

◆ operator=() [2/2]

SmallFunc & gaia::util::SmallFunc::operator= ( SmallFunc &&  other)
inlinenoexcept

Move-assigns the wrapper.

Parameters
otherSource wrapper.
Returns
Reference to this wrapper.

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