literals

Steven Schveighoffer schveiguy at yahoo.com
Sun Mar 28 12:09:37 PDT 2010


On Sun, 28 Mar 2010 09:26:43 -0400, so <so at so.do> wrote:

> On Sun, 28 Mar 2010 18:18:20 +0400, Fawzi Mohamed <fawzi at gmx.ch> wrote:
>
>> how?
>
> When you divide 1.0 / 5, compilers warns or implicitly converts "5" to a  
> floating point type, am i wrong?
> I told you what i want, remember "zero implicit cast"
>
>> yes you can write a template that automatically "upconverts" to float,  
>> but I don't think that is the correct thing for a default thing to do,  
>> why do you alway want to have floats as result?
>
> I don't always want float as result, but check the function again.
> What happens there? "1.0 / m" which will result a floating point type,  
> what code suggests is, that this type will be "T"
>

What you want is implicit function template instantiation based on the  
return type.  D doesn't do that, it doesn't even allow overloading based  
on the return type.  However, you can infer the return type using auto:

auto inv(T)(T m)
{
    return 1.0/m;
}

-Steve



More information about the Digitalmars-d mailing list