Template Parameter Deduction

Paul D Anderson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 11 15:45:12 PDT 2015


On Wednesday, 11 March 2015 at 22:44:12 UTC, Paul D Anderson 
wrote:
> This used to work in D2.065:
>
> given
>
> 1) public T mul(T)(in T x, in T y,
>     Context context = T.context) if (isDecimal!T)
>     // one template parameter for the two input values
>
> and
>
> 2) public T mul(T, U)(in T x, U n, Context context = T.context)
>     if (isDecimal!T && isIntegral!U)
>     // two different template parameters for the two input 
> values
>
> then
>
> 3) dec9 arg1 = dec9("1.20");
>    long arg2 = 3;
>    result = mul(arg1, arg2);
>    // correctly deduced function
>
> But now (D2.066.1) either 1) has to be changed to
>
> 1) public T mul(T, U)(in T x, U y, Context context = T.context)
>     if (isDecimal!T && isDecimal!U)
>     // two identical template parameters for the two input 
> values
>
> or 3) has to be changed to
>
> 3) dec9 arg1 = dec9("1.20");
>    long arg2 = 3;
>    result = mul!(dec9,long)(arg1, arg2);
>    // template parameters have to be made explicit
>
> Is this expecded behavior?
>
> Paul

or *expected* behavior


More information about the Digitalmars-d-learn mailing list