On 04/15/2018 02:04 PM, vladdeSV wrote:

     void foo(T...)(T args)
         writefln("expected: %s", [1,2,3]);
         writefln("actual: %s", args);

The code above will output

     expected: [1, 2, 3]
     actual: 1

How would I go on about to print all the arguments as I expected it, using "%s"?

    writefln("%s", [args]);

Or avoiding the allocation:

    import std.range: only;
    writefln("%s", only(args));

You could also change the `args` parameter to give you a stack-based array:

    void foo(T)(T[] args ...)
        writefln("%s", args);

I do not understand why only a `1` is printed in the actual result.


    writefln("actual: %s", args);

becomes this:

    writefln("actual: %s", args[0], args[1], args[2]);

So there are three arguments after the format string. The %s placeholder only refers to the first one. The others are ignored.

Reply via email to