I'm trying to make my template function produce a compile-time error if the non-specialized base version is instantiated. I tried the usual compile-time assert pattern (negative array size) but the compile is failing even when the template is not instantiated. Any thoughts on how to to make it fail if and only if the base-template function is instantiated?
template<class Foo> void func(Foo x) {
// I want the compiler to complain only if this function is instantiated.
// Instead, the compiler is complaining here at the declaration.
int Must_Use_Specialization[-1];
}
template<> void func(int x) {
printf("Hi\n");
}