18 #ifndef ION_BASE_FUNCTIONCALL_H_
19 #define ION_BASE_FUNCTIONCALL_H_
23 #include "base/macros.h"
62 template <
typename ReturnType,
typename... Types>
69 args_(std::make_tuple(std::forward<Types>(args)...)) {}
76 args_(std::make_tuple(std::forward<Types>(args)...)) {}
84 this->ExpandArgsAndCall(free_func_,
85 SequenceGenerator<
sizeof...(Types)>{});
87 this->ExpandArgsAndCall(std_func_,
88 SequenceGenerator<
sizeof...(Types)>{});
93 const typename std::tuple_element<I, std::tuple<Types...> >
::type&
GetArg()
95 return std::get<I>(args_);
100 void SetArg(
const typename std::tuple_element<I, std::tuple<Types...> >::
type&
102 std::get<I>(args_) = value;
108 template <
size_t... Indicies>
struct Sequence {};
111 template <
size_t N,
size_t... Indices>
112 struct SequenceGenerator : SequenceGenerator<N - 1U, N - 1U, Indices...> {};
115 template <
size_t... Indices>
116 struct SequenceGenerator<0U, Indices...> :
Sequence<Indices...> {};
122 template <
typename Func,
size_t... Indices>
124 func(std::get<Indices>(args_)...);
129 ReturnType (*free_func_)(Types...);
130 std::function<ReturnType(Types...)> std_func_;
133 std::tuple<Types...> args_;
139 #endif // ION_BASE_FUNCTIONCALL_H_
FunctionCall wraps an arbitrary call to a function, including its arguments.
void SetArg(const typename std::tuple_element< I, std::tuple< Types...> >::type &value)
Sets the Ith argument of the stored arguments to the passed value.
FunctionCall(ReturnType(*func)(Types...), Types &&...args)
Constructor for a free function (general non-member function).
void operator()() const override
Calls the wrapped function with the stored arguments.
~FunctionCallBase() override
FunctionCallBase does nothing but define a virtual operator() to allow containers of arbitrary Functi...
Allocatable is an abstract base class for classes whose memory is managed by an Allocator.
virtual void operator()() const =0
FunctionCall(const std::function< ReturnType(Types...)> &func, Types &&...args)
Constructor for a std::function (returned by std::bind()).
const std::tuple_element< I, std::tuple< Types...> >::type & GetArg() const
Returns a const reference to the Ith argument of the function call.