An idiom for disabling implicit conversions

Don nospam at nospam.com
Fri Mar 19 02:35:59 PDT 2010


bearophile wrote:
> Don:
> 
> Do you know why this semantics:
> 
>> void add(Tulong)(Tulong x)   if ( is(Tulong == ulong) )
> 
> Is different from this one?
> 
> void add(Tulong:ulong)(Tulong x) {
> 
> This page says:
> http://www.digitalmars.com/d/2.0/templates-revisited.html
> T:int,        // T must be int type
> So it seems the same as the version with the template constraint.

It isn't. It's the same as:

add(ulong x)
which leads to an ambiguity with add(long x).

Template constraints are considerably more powerful than template 
specialisation.

> 
> Can't the D2 semantics of (Tulong:ulong) be redefined to become the same of the version with template constraint if(is(Tulong==ulong)) to remove this special case from D?

Not without loss of capability.



More information about the Digitalmars-d mailing list