Why code failed to compile for foo2?

Adam Ruppe destructionator at gmail.com
Sat Dec 11 22:59:52 UTC 2021


On Saturday, 11 December 2021 at 22:50:45 UTC, apz28 wrote:
> void foo2(T)(Unqual!T x) if(isUnsigned!T) {}

This means it treats foo2 as if it doesn't exist unless T is 
unsigned...

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

And this is telling you it had a signed value - int - which means 
it doesn't match.

For the other ones, the functions still exist, so it does 
whatever conversion it needs. Whereas with the template that 
constraint means the compiler acts like it doesn't exist at all 
and thus doesn't even attempt an automatic conversion.


More information about the Digitalmars-d-learn mailing list