Varargs and default arguments

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Oct 7 01:34:26 PDT 2015


On Wednesday 07 October 2015 02:22, Steven Schveighoffer wrote:

> On 10/6/15 4:27 PM, anonymous wrote:
[...]
>> void foo(T...)(string str=null, T args = T.init) {
[...]
> I find it quite fascinating that in anonymous' solution, the T.init 
> doesn't ever actually get used!

It's not used with IFTI, but if you instantiate the template explicitly, the 
defaults arguments come up.

Or rather, they should come up. It doesn't seem to work:

----
void foo(T ...)(T args = T.init) {}
void main()
{
    foo!(int, float)(); /* Error: foo (int _param_0, float _param_1) is not 
callable using argument types () */
}
----

I filed an issue: https://issues.dlang.org/show_bug.cgi?id=15170


More information about the Digitalmars-d-learn mailing list