Varargs and default arguments
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Oct 6 17:22:43 PDT 2015
On 10/6/15 4:27 PM, anonymous wrote:
>
> You can put an expression tuple ("expression AliasSeq"??) there. T.init is
> one that always fits T's types. But you could generate one with different
> values, too.
>
> ----
> void foo(T...)(string str=null, T args = T.init) {
> //...
> }
> void main()
> {
> foo();
> foo("");
What is T in this case? I wondered, and it is an empty expression tuple
(prints out as "()"). Interesting.
Note, this doesn't seem to work on 2.067.
There are other ways to solve this too:
void foo() {return foo(null);}
void foo(T...)(string str, T args) {...}
I find it quite fascinating that in anonymous' solution, the T.init
doesn't ever actually get used!
-Steve
More information about the Digitalmars-d-learn
mailing list