How to specialize variadic template function that has const reference for an argument?
Example:
template<typename T, typename... Args>
T foo(Args... args) = delete;
template<> int foo(int a, const char* str, const Test& t) { .... } // Fails to compile
//template<> int foo(int a, const char* str, Test ) { .... } // Ok
int main() {
auto i = foo<int>(10, "test string!", t);
return 0;
}
When invoking function foo with declared const Test&
argument, the compiler fails to see specialized function and fallbacks to deleted function:
error: use of deleted function ‘T foo(Args ...) [with T = int; Args = {int, const char*, Test}]’
auto i = foo<int>(10, "test string!", t);
The above code compiles fine if I remove const reference from argument. What am I doing wrong?
The code can be found here