When you write a call to void f(...) {}, a function that accepts as many parameters as you send gets instantiated right? |
No: this is a run-time mechanism. In fact,
f() might live in a library, where its source code is not available to the compiler. The compiler needs to see that source code if it plans to write a different function for each number of arguments.
Because of this, only the types already known to the implementation can be retrieved from inside a varargs function:
printf() cannot handle
std::string, for instance, because it does not know what it is - much less any user-defined type.
Additionally, this is a C feature, and C does not support function overloading.
In order for a varargs function to retrieve the arguments passed to it, the
caller has to place the arguments in a known order in a known place (depending on the ABI). In addition, the
callee has to know the types of arguments passed to it. For
printf, for example, this information is encoded in the format string:
%d means
int, for example - and
va_arg knows where to look in order to find the next
int argument.
@dutch
In OP's case we don't care about the arguments - the ellipsis is only there as a C++ meta-programming trick used to manipulate overload resolution. But yeah, it would need ABI-specific inline assembly.