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 21:10:32 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.
Maybe I am being silly, but it isn't possible to determine T
here. Independent of what T is the input parameter would be an
int (which the compiler can't see but we can) but the output
depends on T which can't be deduced.
More information about the Digitalmars-d-learn
mailing list