Parameters declared as the alias of a template won't accept the arguments of the same type.

Loara loara at noreply.com
Tue May 3 09:59:16 UTC 2022


On Monday, 2 May 2022 at 19:17:19 UTC, Stanislav Blinov wrote:
> On Monday, 2 May 2022 at 16:29:05 UTC, Loara wrote:
>
>> Template deduction for aliased function parameter is a very 
>> tricky argument and it's not so simple to handle in certain 
>> cases. Consider for example this code:
>>
>> ```d
>>     template MyAlias(T){
>>       alias MyAlias = int;
>>     }
>>
>>     T simp(T)(MyAlias!T val){
>>       return T.init;
>>     }
>>
>>     int main(){
>>       simp(3);//Impossible to deduce T
>
> Why? That's the issue. It is very possible to deduce T here. 
> Compiler just isn't trying. The function takes an int. Doesn't 
> take a rocket scientist to figure that one out.

No, an alias is not a type and it'll be immediately 
substitutedwith the aliased symbol. You should use 
[typedefs](https://dlang.org/phobos/std_typecons.html#Typedef) in 
order to create a different type.




More information about the Digitalmars-d-learn mailing list