Template specialization question
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Nov 24 09:59:55 PST 2016
On 11/24/2016 06:47 PM, Steven Schveighoffer wrote:
> void foo(T)(T t){writeln("a");}
> void foo(T...)(T t){writeln("b");}
>
> foo(1);
>
> Compiles? If so, which prints out?
>
> I was surprised by the answer. I can't find docs for it. Is the behavior
> intended?
Took me a bit to find it, but it is documented:
"If both a template with a sequence parameter and a template without a
sequence parameter exactly match a template instantiation, the template
without a TemplateSequenceParameter is selected."
https://dlang.org/spec/template.html#variadic_template_specialization
More information about the Digitalmars-d-learn
mailing list