The answer to this question picks apart a function type using a class template:
template <typename T>
struct function_args {};
template <typename R, typename... Args>
struct function_args<R(Args...)> {
using type = tuple<Args...>;
};
template <typename T>
using decltypeargs = typename function_args<T>::type;
As I studied what was being done here I tried to rewrite function_args
. I attempted to do this using a function so as to eliminate the need for the decltypeargs
template. But found myself mired in improper syntax:
template <typename T>
tuple<> myTry();
template <typename Ret, typename... Args>
tuple<Args...> myTry<Ret(Args...)>();
My hope had been to call decltype(myTry<decltype(foo)>())
to get the tuple
type instead of having to call decltypeargs<decltype(foo)>
. Is there a way to do this with a function declaration?
Functions cannot be specialized like that, but you don't need to specialize a function for this. Tested with gcc 6.1.1:
With a function, you can either just reuse the same type trait from before:
Or you can reimplement the same with functions. You can't partially specialize function templates, but you can overload: