I am trying to deduce callback function parameters from a callback given as a template parameter. I have found this previous answer: Can you extract types from template parameter function signature which looks like it'd be the answer, but somehow I cannot get this to work for what I want.
I have the following code:
#include <tuple>
template<typename S>
struct signature;
template<typename R, typename... Args>
struct signature<R(Args...)>
{
using return_type = R;
using argument_type = std::tuple<Args...>;
};
template <auto callback>
void check_callback()
{
using callback_type = decltype(callback);
using arg1 = std::tuple_element_t<0, signature<callback_type>::argument_type>;
}
int main()
{
}
When compiling this with clang 6.0 as c++17 I get the following error:
error: template argument for template type parameter must be a type; did you forget 'typename'?
If I change the line defining callback_type to something like
using callback_type = void(int);
then it suddenly works, so given a valid function signature the code seems to work. Why won't it work when using decltype on a function coming from a template parameter?