On Thursday, 14 March 2024 at 20:58:21 UTC, Andy Valencia wrote:
>On Thursday, 14 March 2024 at 18:05:59 UTC, H. S. Teoh wrote:
>...
The best way to do multi-type varags in D is to use templates:
import std;
void myFunc(Args...)(Args args) {
Thank you. The first parenthetical list is of types, is it not? I can't find anywhere which says what "type" is inferred for "Args..."? (gdb pretends like "arg" is not a known symbol.) Is it basically a tuple of the suitable type?
Andy
Most of the time the variadic template parameters are infered from the run time parameters. In that case indeed Args
will be a type tuple of args
types.
void myFunc(Args...)(Args args) {}
myFunc(0,0.1); // is like the more verbose `myFunc!(int,double)(0,0.1)`
However explicit instantiation can take whatever is known at compile time, such as constant expressions or even certain static variables. So that is rather called an alias sequence
in D.
That being said and with the signature of myFunc
that will effectively only work if Args
is made of types.
About debugging, each individual runtime arg can be inspected using a bit of knowledge of D internals.
As you can see the elements are named following this pattern __param_[0-9]+
.
So with gdb used as CLI, $ p __param_0
will (🤞🤞) print the first variadic element, and so on.