I'm not great at template metaprogramming, so apologies if this is a dumb question.
I have a type like
template<int n>
struct S
{
typedef decltype(n) type_of_n;
// ...
};
and I'd like to write functions that look something like
template<
typename T,
typename T::type_of_n n,
typename = std::enable_if_t<std::is_same<T, S<n>>::value>>
void f(const T &) { /* ... */ }
with the idea being that if the type of the non-type template argument to S changes at some point in the future (say to std::size_t or int64_t or something) then calling code will just continue working. But I'm not sure how to get the compiler to infer both T and n in tandem here.
The only things I've come up with are basically hacks:
- Do something like
typedef int type_of_S_noutside ofS. - Write something like
S<0>::type_of_ninstead of actually inferring the type
Is what I'm trying to do possible? If not, is there a "cleaner" way to do it than the hacks above?