challenge: implement the max function
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Sun Jan 21 12:38:31 PST 2007
Lionello Lunesu wrote:
> "Andrei Alexandrescu (See Website For Email)"
> <SeeWebsiteForEmail at erdani.org> wrote in message
> news:45B3B243.2010103 at erdani.org...
>> 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;
>
> ...when would that be useful? And, what happens if arr[0]==arr[1] ?
Can't immediately think up an example of usefulness, but what presumably
happens if they're equal is that one of them gets reduced by 10% (and
rounded to the accuracy of typeof(arr[0])).
More information about the Digitalmars-d
mailing list