I have the following code, which defines a template struct W
that exports a type T
that's based on the template argument to W
:
#include <iostream>
using namespace std;
template <unsigned N>
struct Y {};
template <unsigned N>
struct W {
using T = Y<N>;
};
I then defined this template function that looks at this type T
:
template <unsigned N>
void foo (const typename W<N>::T& in) {
//--
}
The problem here is that if I try calling this function from main
using one of the types exported as T
, it doesn't compile. For example, if I write
int main() {
Y<2> y;
foo(y);
return 0;
}
I get a compiler error that says
template argument deduction/substitution failed:
couldn't deduce template parameter
What's going on here?