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

ag0aep6g anonymous at example.com
Mon May 2 20:16:04 UTC 2022


On 02.05.22 21:17, Stanislav Blinov wrote:
> On Monday, 2 May 2022 at 16:29:05 UTC, Loara wrote:
[...]
>> ```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.

I take it your answer is that T must be int. But that's nonsense. 
MyAlias maps all types to int. It's not a bijection, you can't turn it 
around.


More information about the Digitalmars-d-learn mailing list