Accessing __traits(identifier) for variadic function arguments

Alexa Schor alexaschor at gmail.com
Fri Oct 11 18:16:57 UTC 2024


On Friday, 11 October 2024 at 06:04:44 UTC, Salih Dincer wrote:
> On Friday, 11 October 2024 at 03:01:54 UTC, Alexa Schor wrote:
>> [...]
>
> ```d
> import std.stdio, core.interpolation;
> void show(Args...)(InterpolationHeader hdr, Args args, 
> InterpolationFooter ftr)
> {
>   foreach (arg; args)
>   {
>     static if (is(typeof(arg) == InterpolatedExpression!code, 
> string code))
>       code.write;
>     else static if (is(typeof(arg) == InterpolatedLiteral!str, 
> string str))
>       str.write;
>     else write(" = ", arg);
>   }
>   writeln();
> }
>
> void main()
> {
>    int a = 5, b = 22;
>    show(i`$(a), $(b), $(a + b)`);
>    // a = 5, b = 22, a + b = 27
> }
> ```
> SDB at 79

Oh how fantastic! What a great feature, thank you so much for 
your assistance.
Take care, and have a great day.

Alexa


More information about the Digitalmars-d-learn mailing list