MIN MAX problem
Andrei Alexandrescu (See Website For Email)
SeeWebsiteForEmail at erdani.org
Tue Mar 13 22:11:57 PDT 2007
Walter Bright wrote:
> torhu wrote:
>> You can use typeof to get the common type, like this:
>>
>> typeof(T + U) max(T, U)(T arg1, U arg2)
>> {
>> return arg1 > arg2 ? arg1 : arg2;
>> }
>
> The + isn't always defined, so you can use:
>
> typeof(true ? cast(T)0 : cast(U)0) max(T, U)(T x1, U x2)
> {
> return x1 > x2 ? x1 : x2;
> }
Is there a plan to allow:
typeof(true ? x1 : x2) max(T, U)(T x1, U x2)
{
return x1 > x2 ? x1 : x2;
}
Andrei
More information about the Digitalmars-d
mailing list