I've recently learned that I cannot:
- Take the address of an undefined function
- Take the address of a templatized function with a type it would fail to compile for
But I've also recently learned that I can call decltype
to get the return type of said function
So an undefined function:
int foo(char, short);
I'd like to know if there's a way that I can match the parameter types to the types in a tuple
. This is obviously a meta programming question. What I'm really shooting for is something like decltypeargs
in this example:
enable_if_t<is_same_v<tuple<char, short>, decltypeargs<foo>>, int> bar;
Can anyone help me understand how decltypeargs
could be crafted?
For non-overloaded functions, pointers to functions, and pointers to member functions, simply doing
decltype(function)
gives you the type of the function in an unevaluated context, and that type contains all the arguments.So to get the the argument types as a tuple, all you need are a lot of specializations:
With that:
This requires you to write
decltypeargs<decltype(foo)>
.With C++17, we will have
template <auto>
, so the above can be:and you'd get the
decltypeargs<foo>
syntax.