Template specialization question

Stefan Koch via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Nov 24 10:31:11 PST 2016


On Thursday, 24 November 2016 at 17:47:04 UTC, 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?
>
> -Steve

That is expected.
The general rule is go for the narrowest match.
Since a matches a smaller set then b.
a is selected.


More information about the Digitalmars-d-learn mailing list