challenge: implement the max function
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Sun Jan 21 13:44:53 PST 2007
Lionello Lunesu wrote:
> "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? :)
That would be implementation-dependent.
If you need it to be a specific one, that's an additional requirement.
So implement the function yourself ;).
But perhaps it doesn't matter?
Or maybe the caller knows it just can't happen?
More information about the Digitalmars-d
mailing list