I want to make a class that will take multiple functions (function pointers, lambdas, classes with operator()
, etc), save them in a tuple, and then call all of them with passed arguments (assuming that each function is callable with them). I also want to put it under templated interface so that the caller only knows about required arguments and return types of functions (which will be required only for bool
specialization). Here’s what I approximately am trying to achieve (and full version):
template<typename Ret, typename... Args>
class MultiCall
{
public:
virtual void operator()(Args... args_) = 0;
};
template<typename Ret, typename... Args, typename... Fs>
class MultiCallImpl : public MultiCall<Ret, Args...>
{
public:
MultiCallImpl(Fs... fs_) :
m_funcs(fs_...)
{
}
virtual void operator()(Args... args_) override
{
((std::get<Fs>(m_funcs)(args_...)), ...);
}
private:
std::tuple<Fs...> m_funcs;
};
If I remove both Ret
and Args
, it compiles fine, but with any of them it can’t deduce types of functions and it complains about Args
being in the middle of variadic template, although, as far as I know, its possible to put multiple parameter packs in the template if they can be automatically deduced. Is it possible to fix this code to achieve what I want?