"%s"-format template function arguments
Dennis
dkorpel at gmail.com
Sun Apr 15 12:24:09 UTC 2018
On Sunday, 15 April 2018 at 12:04:19 UTC, vladdeSV wrote:
> How would I go on about to print all the arguments as I
> expected it, using "%s"?
You can expand the template arguments into an array by putting it
into square brackets: [args]. You can format an array with the
default notation using %s, for a custom format you can use %( and
%). See https://dlang.org/phobos/std_format.html
```
void main() {
foo(1, 2, 3);
}
void foo(T...)(T args) {
writefln("%s", [args]); // prints [1, 2, 3]
writefln("%(%s; %)", [args]); //custom ; separator, prints 1;
2; 3
}
```
More information about the Digitalmars-d-learn
mailing list