I know how to infer the template parameter from an instantiation of a class template:
template <typename T>
struct foo {};
template <typename T>
struct foo_param;
template <typename T>
struct foo_param< foo<T> > {
using type = T;
};
But I am lost at doing the same for a function template. The naive
template <typename T>
void bar() {}
template <auto F>
struct bar_param;
template <typename T>
struct bar_param< &bar<T> > {
using type = T;
};
fails with
<source>:21:19: error: template argument '& bar<T>' involves template parameter(s)
21 | struct bar_param< &bar<T> > {
| ^~~~~~~
I think I do understand the error (actually it turned out that I didn't but thats a case for a different question), but I don't know how to avoid it. How can I infer eg int
given a &bar<int>
?