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

JG someone at somewhere.com
Mon May 2 17:21:53 UTC 2022


On Monday, 2 May 2022 at 16:29:05 UTC, Loara wrote:
> On Sunday, 1 May 2022 at 03:57:12 UTC, Elfstone 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
>       simp( cast(MyAlias!string) 4);//Also invalid since 
> MyAlias!string is exactly int
>       simp!string(4);//Ok, no parameter deduction
>     }
> ```


I don't really see what your example is trying to show. This also 
doesn't work,
and in my mind should be equivalent:
```d
T simp(T)(int val) {
     return T.init;
}

int main() {
     simp(3);//Impossible to deduce T
}
```


More information about the Digitalmars-d-learn mailing list