15 #ifndef EMP_GENERIC_FUNCTION_H 16 #define EMP_GENERIC_FUNCTION_H 19 #include "../base/assert.h" 35 template <
typename RETURN,
typename... Ts>
auto Call(Ts &&... args);
38 template <
typename RETURN,
typename... Ts>
auto operator()(Ts &&... args) {
39 return Call<RETURN, Ts...>( std::forward<Ts>(args)... );
43 template <
typename T>
auto Convert();
50 template <
typename RETURN,
typename... PARAMS>
53 std::function<RETURN(PARAMS...)>
fun;
56 template <
typename... Ts>
57 Function(Ts &&... args) : fun(
std::forward<Ts>(args)...) { ; }
60 template <
typename... Ts>
61 RETURN
Call(Ts &&... args) {
return fun(std::forward<Ts>(args)...); }
64 template <
typename... Ts>
65 RETURN
operator()(Ts &&... args) {
return fun(std::forward<Ts>(args)...); }
68 template <
typename RETURN,
typename... Ts>
70 using fun_t =
Function<RETURN(Ts...)>;
74 fun_t * fun = (fun_t *)
this;
75 return fun->Call( std::forward<Ts>(args)... );
RETURN operator()(Ts &&...args)
Forward all args to std::function call.
Definition: GenericFunction.h:65
Definition: BitVector.h:785
auto Call(Ts &&...args)
A generic form of the function call operator; use arg types to determine derived form.
Definition: GenericFunction.h:69
Definition: GenericFunction.h:29
std::function< RETURN(PARAMS...)> fun
Definition: GenericFunction.h:53
virtual ~GenericFunction()
Definition: GenericFunction.h:32
auto operator()(Ts &&...args)
A generic form of the function call operator; use arg types to determine derived form.
Definition: GenericFunction.h:38
If we are in emscripten, make sure to include the header.
Definition: array.h:37
Function(Ts &&...args)
The std::function to be called.
Definition: GenericFunction.h:57
Definition: GenericFunction.h:47
#define emp_assert(...)
Definition: assert.h:199
auto Convert()
Convert this GenericFunction into a derived emp::Function.
Definition: GenericFunction.h:78
RETURN Call(Ts &&...args)
Forward all args to std::function call.
Definition: GenericFunction.h:61