MIN MAX problem

freeagle dalibor.free at gmail.com
Mon Mar 12 15:31:44 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;
> }
  could you please explain what this means? coz i'd say it always returns T

typeof(true ? cast(T)0 : cast(U)0)

And, i think this wont work for classes that overload the >,< etc 
operator, as you can't do cast(class)0, can you?



More information about the Digitalmars-d mailing list