Template function specialization doesn't work

Steven Schveighoffer schveiguy at gmail.com
Tue Jul 7 21:02:51 UTC 2020

On 7/7/20 4:21 PM, IGotD- wrote:
> On Tuesday, 7 July 2020 at 20:14:19 UTC, IGotD- wrote:
>> Thank you, that worked and now it picked the correct overloaded 
>> function. I don't understand why and it is a bit counter intuitive. 
>> Why two template arguments as I'm not even us using U?
>> If you look at the article
>> https://dlang.org/articles/templates-revisited.html#specialization
>> Then it mentioned that (T : T*) would work. Intuitively, then you 
>> would think (T : T[]) would work.
> Here (T : T[]) is even the example with the correct double[] type as a 
> correct example as well.
> https://dlang.org/spec/template.html#parameters_specialization
> I'm confused.

That's not IFTI, that's template instantiation.

I bet if you did:


it would pick the second one.

there is some extra magic going on for IFTI, and I'm not sure how it 
figures out what to do. I would agree with you that if explicit 
templates use that rule, so should IFTI. But perhaps there's a good 
reason why it can't be done.

So possibly:

overloadedFunction(arSlice) => Pattern match `ref T[]` to `ubyte[]` => T 
is ubyte => Check ubyte for T : T[], no match.


More information about the Digitalmars-d-learn mailing list