Why code failed to compile for foo2?

apz28 home at home.com
Sat Dec 11 22:50:45 UTC 2021

void foo1(ubyte x) {}
void foo1(ushort x) {}
void foo1(uint x) {}
void foo1(ulong x) {}

import std.traits : isUnsigned, Unqual;
void foo2(T)(Unqual!T x) if(isUnsigned!T) {}

     void main()
         import std.math;

         int s = 1;
         foo2(abs(s)); //failed?

onlineapp.d(15): Error: template `onlineapp.foo2` cannot deduce 
function from argument types `!()(int)`
onlineapp.d(7):        Candidate is: `foo2(T)(Unqual!T x)`

More information about the Digitalmars-d-learn mailing list