(In reply to comment #0)
> -----
> import std.stdio;
>
> void test(T...)(T args)
> {
> writefln("%s", args);
> writeln(args);
> }
>
> void main()
> {
> test(1, 2, 3, 4);
> }
> -----
>
> $ dmd test.d
> > 1
> > 1234
Well, what did you expect?
I personally would've expected it to error on the basis of having received too many arguments (or was that error phased out?), but this behaviour looks correct to me.
Comment #2 by andrej.mitrovich — 2014-02-14T12:47:18Z
(In reply to comment #1)
> Well, what did you expect?
I guess I'm looking for some kind of eager version of %s? This isn't necessarily a bug, but could be an enhancement request (unless it can already be done with another format spec?).
Comment #3 by jakobovrum — 2014-02-14T12:49:06Z
(In reply to comment #2)
> (In reply to comment #1)
> > Well, what did you expect?
>
> I guess I'm looking for some kind of eager version of %s? This isn't
> necessarily a bug, but could be an enhancement request (unless it can already
> be done with another format spec?).
It would necessitate treating all trailing arguments equally (which would arguably only make sense for %s).
Comment #4 by andrej.mitrovich — 2014-02-14T12:52:14Z
Ah I know of a cute trick though:
writefln("%s", args.only);
Comment #5 by andrej.mitrovich — 2014-02-14T12:53:09Z
(In reply to comment #4)
> Ah I know of a cute trick though:
>
> writefln("%s", args.only);
And come to think of it, I think bearophile has a couple of format() enhancement requests specifically for tuples.
Comment #6 by andrej.mitrovich — 2014-02-14T12:55:28Z
(In reply to comment #5)
> (In reply to comment #4)
> > Ah I know of a cute trick though:
> >
> > writefln("%s", args.only);
>
> And come to think of it, I think bearophile has a couple of format()
> enhancement requests specifically for tuples.
Specifically, the following works for arrays but not for tuples:
writefln("%(%s %)", [1, 2]); // prints "1 2"
Perhaps if we could modify the syntax a little bit..
writefln("%!(%s %)", TypeTuple!(1, 2)); // would print "1 2"
Disregard the TypeTuple misnomer though. :)
Comment #7 by jakobovrum — 2014-02-14T12:58:29Z
(In reply to comment #6)
> (In reply to comment #5)
> > (In reply to comment #4)
> > > Ah I know of a cute trick though:
> > >
> > > writefln("%s", args.only);
> >
> > And come to think of it, I think bearophile has a couple of format()
> > enhancement requests specifically for tuples.
>
> Specifically, the following works for arrays but not for tuples:
>
> writefln("%(%s %)", [1, 2]); // prints "1 2"
>
> Perhaps if we could modify the syntax a little bit..
>
> writefln("%!(%s %)", TypeTuple!(1, 2)); // would print "1 2"
>
> Disregard the TypeTuple misnomer though. :)
It is no surprise that tuples (aka template argument list) work differently from arrays, considering their auto-expansive behaviour.
bearophile's ER pertains std.typecons.Tuple, not in-built "type tuples".