MIN MAX problem

torhu fake at address.dude
Tue Mar 13 13:30:54 PDT 2007


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



More information about the Digitalmars-d mailing list