Template argument deduction not working with template specialization
Steven Schveighoffer
schveiguy at gmail.com
Sun Jan 17 16:42:27 UTC 2021
On 1/17/21 11:22 AM, Paul wrote:
> While trying to use template specializations I noticed the argument
> deductions do not yield the same version as the ones yielded when being
> explicit.
> Example:
>
>> uint a = 1;
>> uint[] b = [2];
>> TFoo(a);
>> TFoo!(uint[])(b);
>
>> void TFoo(T)(T a) {
>> pragma(msg, "T: " ~ T.stringof);
>> }
>>
>> void TFoo(T : T[])(T[] a) {
>> pragma(msg, "T[]: " ~ T.stringof);
>> }
>
> I noticed that an automatically deduced TFoo call always yields the
> first, while TFoo!(uint[]) yields the array version if present, and
> defaults to the first elsewise.
>
> Am I incorrect in expecting the same behavior when (ab)using argument
> deduction or does my usage make sense? I tried searching for this
> combination (deduction & specialization) but couldn't find another forum
> post / documentation example.
I've always hated that aspect of specialization. I don't really
understand why it's valid (how can T be T[]?)
This works:
void TFoo(T : U[], U)(T a)
-Steve
More information about the Digitalmars-d-learn
mailing list