I have a function with a parameter pack:
template<typename... Targs>
void tprintf(const char* format, Targs... args) {}
(the implementation shouldn't matter, just the signature). I want to add source position as default argument, using the GCC/Clang builtins. Something like
template<typename... Targs>
void tprintf(const char* format, Targs... args,
const char* file = __builtin_FILE(),
unsigned line = __builtin_LINE()) {}
This compiles, but calls to it are not passing parameters to args
as I hoped; e.g.
tprintf("%d%s", 0, "a");
gives (on Clang 10)
<source>:7:5: error: no matching function for call to 'tprintf'
tprintf("%d%s", 0, "a");
^~~~~~~
<source>:2:6: note: candidate function template not viable: no known conversion from 'const char [2]' to 'unsigned int' for 3rd argument
void tprintf(const char* format, Targs... args,
^
which seems to indicate args
is empty, 0
is file
, and "a"
is line
.
Actually, while writing the question I've found that explicitly passing Targs
works:
tprintf<int, char*>("%d%s", 0, "a");
Is it possible to avoid this?