how to get rid of "cannot deduce function from argument types" elegantly

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 14 07:30:38 PDT 2016


On 6/14/16 6:05 AM, pineapple wrote:
> On Monday, 13 June 2016 at 22:54:13 UTC, Ali Çehreli wrote:
>> Tree!T tree(TL, T, TR)(TL left, T node, TR right) {
>>   return new Tree!T(left, node, right);
>> }
>>
>
> There's also this:
>
>     Tree!T tree(TL, T, TR)(TL left, T node, TR right) if(
>         (is(TL == Tree!T) || is(TL == typeof(null))) &&
>         (is(TR == Tree!T) || is(TR == typeof(null)))

Alternative: if(is(typeof({Tree!T x = TL.init; x = TR.init; })))

This may seem similar, but actually can accept things that convert to 
Tree!T as well.

The issue with the OP code is that the compiler is trying to match T 
with the two null parameters, and can't work out the deduction.

-Steve


More information about the Digitalmars-d-learn mailing list