GenericFunction.hpp

Based on std::function, but with a common base class.

Todo:

Need to setup Call on GenericFunction to just take a function signature as a template argument, rather than listing all types.

Note

Status: ALPHA

class GenericFunction
#include <GenericFunction.hpp>

The Function templated class behaves almost identically to std::function, but can be reduced to the GenericFunction base class which is NOT templated.

An GenericFunction object can be converted back into the derived type with the .Convert<return(args…)>() member function.

Subclassed by Function< RETURN(PARAMS…)>

Public Functions

inline virtual ~GenericFunction()
virtual size_t NumArgs() const = 0
template<typename RETURN, typename ...Ts>
auto Call(Ts&&... args)

A generic form of the function call operator; use arg types to determine derived form.

template<typename RETURN, typename ...Ts>
bool CallOK(Ts&&...)

Test if a function call will succeed before trying it.

template<typename RETURN, typename ...Ts>
bool CallTypeOK()

Test if a function call will succeed before trying it, based only on types.

template<typename RETURN, typename ...Ts>
inline auto operator()(Ts&&... args)

A generic form of the function call operator; use arg types to determine derived form.

template<typename T>
auto Convert()

Convert this GenericFunction into a derived Function.

template<typename T>
bool ConvertOK()

Determine if this GenericFunction can be converted into a derived Function.

template<typename RETURN, typename ...PARAMS>
class Function<RETURN(PARAMS...)> : public GenericFunction
#include <GenericFunction.hpp>

Public Functions

template<typename ...Ts>
inline Function(Ts&&... args)

Forward all args to std::function constructor…

inline virtual size_t NumArgs() const override
template<typename ...Ts>
inline RETURN Call(Ts&&... args)

Forward all args to std::function call.

template<typename ...Ts>
inline RETURN operator()(Ts&&... args)

Forward all args to std::function call.

inline const fun_t &GetFunction() const

Get the std::function to be called.

Protected Types

using fun_t = std::function<RETURN(PARAMS...)>

Protected Attributes

fun_t fun

The std::function to be called.