Partial template specialization problem
Hello,
I'm trying to customize template by partially specializing
it with another template class. However, compiler rejects
the code with error C2975 ("invalid template argument for
'N', expected compile-time constant expression"). Here's the
code:
---------------------------------------
template <int N>
struct X
{
int goo() const { return N; }
};
template <
typename T1,
typename T2,
typename T3
struct Y
{
void foo(T1 v1, T2 v2, T3 v3)
{
std::wcout << __FUNCTION__ << L"\n"
<< v1 << L"; "
<< v2 << L"; "
<< v3 << L"\n";
}
};
template <
typename T2,
typename T3
struct Y<X<int>, T2, T3>
{
void foo(X<int> v1, T2 v2, T3 v3)
{
std::wcout << __FUNCTION__ << L"\n"
<< v1.goo() << L"; "
<< v2 << L"; "
<< v3 << L"\n";
}
};
int _tmain(int argc, _TCHAR* argv[])
{
X<42> x1;
Y<int, double, std::wstring> y1;
Y<X<42>, double, std::wstring> y2;
y1.foo(1, 3.14, L"Hello");
y2.foo(x1, 2.72, L"Special");
return 0;
}
---------------------------------------
Specialization `struct Y<X<int>, T2, T3>' is rejected. If I
specialize with concrete X<N> (for example, `struct Y<X<42>,
T2, T3>'), then everything compiles and runs properly.
However, I cannot predict the value of N, of course.
Is there any workaround?
Thanks in advance
Alex