challenge: implement the max function

Deewiant deewiant.doesnotlike.spam at gmail.com
Sun Jan 21 12:07:52 PST 2007


Xinok wrote:
> Andrei Alexandrescu (See Website For Email) Wrote:
> 
>> Here's a simple challenge: implement the max function. Requirements:
>>
>> a) generic
>> b) efficient
>> c) preserve lvalueness when possible such that one can write e.g.
>>
>> max(arr[0], arr[1]) *= 0.9;
>>
>> d) should accept two or more arguments
>> e) should return the "smartest" type, e.g. max of an unsigned int and 
>> unsigned long should return unsigned long
>> f) short and easy to understand
>>
<snip>
> 
> template max(T1, T2){
> 	typeof(T1+T2) max(T1 a, T2 b){ return a > b ? a : b; }
> }

Doesn't satisfy requirement C, nor, if I understood it correctly (that the
function should accept any number of parameters >= 2), does it satisfy D. Not
sure about E.

-- 
Remove ".doesnotlike.spam" from the mail address.



More information about the Digitalmars-d mailing list