challenge: implement the max function

Lionello Lunesu lionello at lunesu.remove.com
Sun Jan 21 12:55:02 PST 2007


"Frits van Bommel" <fvbommel at REMwOVExCAPSs.nl> wrote in message 
news:ep0j0a$1av2$1 at digitaldaemon.com...
> 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])).

Which one? :)





More information about the Digitalmars-d mailing list