Not sure if this is what you need.
I donβt know how to deploy call_func() parameters package inside call_func() , but if you allow to use auxiliary structure and compiler with C ++ 14 ...
I prepared the following example with return type support.
#include <tuple> template<typename F> struct function_traits; template<typename T, typename R, typename... Args> struct function_traits<R(T::*)(Args...) const> { using return_type = R; using param_types = std::tuple<Args...>; }; template<typename T> struct function_traits : public function_traits<decltype(&T::operator())> {}; template <typename T, typename ... Args> T get_arg (std::tuple<Args...> const & tpl) { return std::get<typename std::decay<T>::type>(tpl); } template <typename ...> struct call_func_helper; template <typename Func, typename Ret, typename ... Args> struct call_func_helper<Func, Ret, std::tuple<Args...>> { template <typename T, typename R = Ret> static typename std::enable_if<false == std::is_same<void, R>::value, R>::type fn (Func const & func, T const & t) { return func(get_arg<Args>(t)...); } template <typename T, typename R = Ret> static typename std::enable_if<true == std::is_same<void, R>::value, R>::type fn (Func const & func, T const & t) { func(get_arg<Args>(t)...); } }; template <typename Func, typename T, typename R = typename function_traits<Func>::return_type> R call_func (Func const & func, T const & id) { using param_types = typename function_traits<Func>::param_types; return call_func_helper<Func, R, param_types>::fn(func, id); } int main() { call_func([](int const & a, char const & b) { }, std::make_tuple(3, '6')); return 0; }
Hope this helps.
max66 source share