Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Private Types | Static Private Member Functions | Private Attributes | List of all members
cFunctionRef< Ret(Args...)> Class Template Reference

A light-weight, type-erased reference to a function object. More...

#include <FunctionRef.h>

Collaboration diagram for cFunctionRef< Ret(Args...)>:
Collaboration graph
[legend]

Public Member Functions

template<class FunctionObject , typename std::enable_if< !std::is_same< typename std::decay< FunctionObject >::type, cFunctionRef >::value, int >::type = 0>
 cFunctionRef (FunctionObject &&a_FunctionObject)
 Construct from a function object. More...
 
Ret operator() (Args... a_Args)
 Call the referenced function object. More...
 

Private Types

using cCallFunction = Ret(*)(void *, Args...)
 

Static Private Member Functions

template<class ObjectType >
static Ret ObjectFunctionCaller (void *a_Callable, Args... a_Args)
 Function that performs the call. More...
 

Private Attributes

void * m_CallableData
 Type erased reference to a callable. More...
 
cCallFunction m_CallFunction
 Function that knows how to call the type erased reference. More...
 

Detailed Description

template<class Ret, class... Args>
class cFunctionRef< Ret(Args...)>

A light-weight, type-erased reference to a function object.

Usage

cFunctionRef is used whenever you call a normal function with a lambda. e.g. one of the cWorld::DoWith functions,

m_World->DoWithChunkAt(BlockPos, [](cChunk & a_Chunk) -> bool
    {
        ...
    }
);

It looks like you're calling it with a lambda but that would require DoWithChunkAt to be a template. The function is really being called with cFunctionRef<bool(cChunk&)> which is constructed from the lambda via a templated constructor. This gives you a generic pointer to the lambda which doesn't depend on the type of the function object it references.

Notes

Definition at line 36 of file FunctionRef.h.

Member Typedef Documentation

◆ cCallFunction

template<class Ret , class... Args>
using cFunctionRef< Ret(Args...)>::cCallFunction = Ret(*)(void *, Args...)
private

Definition at line 74 of file FunctionRef.h.

Constructor & Destructor Documentation

◆ cFunctionRef()

template<class Ret , class... Args>
template<class FunctionObject , typename std::enable_if< !std::is_same< typename std::decay< FunctionObject >::type, cFunctionRef >::value, int >::type = 0>
cFunctionRef< Ret(Args...)>::cFunctionRef ( FunctionObject &&  a_FunctionObject)
inline

Construct from a function object.

Definition at line 45 of file FunctionRef.h.

Member Function Documentation

◆ ObjectFunctionCaller()

template<class Ret , class... Args>
template<class ObjectType >
static Ret cFunctionRef< Ret(Args...)>::ObjectFunctionCaller ( void *  a_Callable,
Args...  a_Args 
)
inlinestaticprivate

Function that performs the call.

Definition at line 64 of file FunctionRef.h.

◆ operator()()

template<class Ret , class... Args>
Ret cFunctionRef< Ret(Args...)>::operator() ( Args...  a_Args)
inline

Call the referenced function object.

Definition at line 55 of file FunctionRef.h.

Member Data Documentation

◆ m_CallableData

template<class Ret , class... Args>
void* cFunctionRef< Ret(Args...)>::m_CallableData
private

Type erased reference to a callable.

Definition at line 77 of file FunctionRef.h.

◆ m_CallFunction

template<class Ret , class... Args>
cCallFunction cFunctionRef< Ret(Args...)>::m_CallFunction
private

Function that knows how to call the type erased reference.

Definition at line 80 of file FunctionRef.h.


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