MIN MAX problem

Walter Bright newshound at digitalmars.com
Tue Mar 13 14:25:41 PDT 2007


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;
}



More information about the Digitalmars-d mailing list