MIN MAX problem

Walter Bright newshound at digitalmars.com
Wed Mar 14 11:13:11 PDT 2007


Andrei Alexandrescu (See Website For Email) wrote:
> 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;
> }

That should probably be made to work, too, but currently it doesn't.



More information about the Digitalmars-d mailing list