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

Stanislav Blinov stanislav.blinov at gmail.com
Mon May 2 20:47:45 UTC 2022


On Monday, 2 May 2022 at 20:16:04 UTC, ag0aep6g wrote:
> 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.

That's not my answer. And it is nonsense, because my answer is - 
what T is irrelevant, MyAlias maps *all* types to int. Therefore 
`simp` takes an int, which is what the caller is passing.


More information about the Digitalmars-d-learn mailing list