varargs when they're not all the same type?
Basile B.
b2.temp at gmx.com
Thu Mar 14 23:13:51 UTC 2024
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.
```d
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.
More information about the Digitalmars-d-learn
mailing list