Varargs and default arguments
Nick Sabalausky via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Oct 6 13:01:53 PDT 2015
Ok, D-style varargs can accept a parameter length of zero:
---------------
void foo(T...)(T args) {
//...
}
foo();
foo(t1, t2);
---------------
Is there any way to stick a param with a default value before that?
---------------
void foo(T...)(string str=null, T args=/+what goes here???+/) {
//...
}
foo();
foo(str);
foo(str, t1, t2);
---------------
Obviously this can be worked around easily enough by splitting it into
two overloads ("foo(string str=null)" and "foo(string str, T args)"),
but is there a way to do it in one?
More information about the Digitalmars-d-learn
mailing list