www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: challenge: implement the max function

reply S. <S s.com> writes:
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
 
 I don't think it's possible to implement the function to the spec in 
 current D, so designs are allowed to invent new features, as long as 
 they define them thoroughly.
 
 Looking forward to any takers!
 
 
 Andrei

Requirements C and E are mutually exclusive.
Jan 22 2007
parent "Andrei Alexandrescu (See Website For Email)" <SeeWebsiteForEmail erdani.org> writes:
S. 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

 I don't think it's possible to implement the function to the spec in 
 current D, so designs are allowed to invent new features, as long as 
 they define them thoroughly.

 Looking forward to any takers!


 Andrei

Requirements C and E are mutually exclusive.

They are not. "When possible" says it all. Andrei
Jan 22 2007