How to properly use variadic templates (functions)?
rempas
rempas at tutanota.com
Tue Dec 21 06:44:36 UTC 2021
On Monday, 20 December 2021 at 22:02:02 UTC, russhy wrote:
> 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);
> }
> ```
This will not do for me because I want to do formatted output and
I need the index. But thanks a lot for tying to help!
More information about the Digitalmars-d-learn
mailing list