How to properly use variadic templates (functions)?

russhy russhy_s at gmail.com
Mon Dec 20 22:02:02 UTC 2021


Here how i'd do, but i'm not sure how to keep track of the index 
of the arguments, i forgot..

```D
import core.stdc.stdio: putc, stdout;

void print(T...)(string prompt, T args)
{
     foreach (a; args)
     {
         alias A = typeof(a);

         static if (is(A : string))
         {
             for (int j = 0; j < a.length; j++)
             {
                 putc(a[j], stdout);
             }
         }
         else
         {
             // handle your other types
             print("", A.stringof);
         }
     }

}

void main()
{
     print("Prompt (ignored)", "Hello", " world!\n", 123);
}
```



More information about the Digitalmars-d-learn mailing list