Detecting inadvertent use of integer division
    Andrei Alexandrescu 
    SeeWebsiteForEmail at erdani.org
       
    Tue Dec 15 14:28:13 PST 2009
    
    
  
Don wrote:
> Andrei Alexandrescu wrote:
>> max takes heterogeneous parameters to catch situations like max(a, 0).
>>
>> Andrei
> 
> Yeah. It's a shame we can't use the ?: type rule for common parameters, 
> since max(T, U) only makes sense when T and U have a common type. So we 
> get code bloat, with unnecessary template instantiations. But it'd be 
> too complicated otherwise, I think. C'est la vie.
La vie n'est pas si mal. Looking through the implementation of max 
you'll see that it carefully selects the compatible types, and also 
computes the correct type for the return value.
I don't think there's much, if any, code bloat as well. The operations 
generated are specialized for the respective types as if you wrote 
things by hand.
Andrei
    
    
More information about the Digitalmars-d
mailing list