MIN MAX problem
BCS
ao at pathlink.com
Tue Mar 13 15:26:35 PDT 2007
Reply to freeagle,
> torhu wrote:
>
>> freeagle wrote:
>>
>>> the result is cast to float when assignment to the variable is being
>>> done. This means you always know of what type you want the result to
>>> be. I say we could move the casting into the function itself, like
>>> this:
>>>
>>> T max(T, U)(T arg1, U arg2)
>>> {
>>> return cast(T) (arg1 > arg2 ? arg1 : arg2);
>>> }
>>> and make it a standard that the type of the first argument will
>>> always be the returning type of the min/max function.
>>>
>> 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;
>> }
> havent seen in the docs something like type adding ?! anyway, my guess
> is that the typeof(T + U) expresion always return the the same type
> for each couple of types. so float + int would always return float?
> what if you want it to return int?
>
The type of every function is fixed at compile time, It can't return a float
sometimes and an int others.
More information about the Digitalmars-d
mailing list