DIP 1023--Resolution of Template Alias Formal Parameters in Template Functions--Community Review Round 1

rikki cattermole rikki at cattermole.co.nz
Fri Sep 6 12:48:34 UTC 2019


On 07/09/2019 12:27 AM, Stefanos Baziotis wrote:
> On Friday, 6 September 2019 at 12:17:11 UTC, rikki cattermole wrote:
>> The D code blocks should have the language set to D (```d ... ```) for 
>> easier reading.
>>
> 
> Thanks, I didn't know about that.
> 
>>
>>
>> Your examples in abstract didn't look right.
>> I ran the second to confirm my suspicion:
>>
>> onlineapp.d(9): Error: undefined identifier T
>>
>>
> 
> Could you paste the example that gave you this error?
> Btw, not all examples are compilable.

This one should be since it is stating current behavior.

Looks like I got it wrong, its third not second:

```
struct TemplateType(T) { }
alias TemplateAlias(T) = TemplateType!T
void templateFunction(TemplateAlias!T arg) { }
```

Two errors (missed the first, semicolon missing).
So:

```
struct TemplateType(T) { }
alias TemplateAlias(T) = TemplateType!T;
void templateFunction(T)(TemplateAlias!T arg) { }
```

>>
>> Here is the test case in your implementation linked that made me 
>> understand your intention for the DIP:
>>
>> ```
>> void main() {
>>     TestAlias!(int, float) testObj;
>>     testFunction(testObj);
>> }
>>
>> struct TestType(T, Q) { }
>> alias TestAlias(T, Q) = TestType!(T, Q);
>> static void testFunction(T, Q)(TestAlias!(T, Q) arg) { }
>> ```
>>
>> Current error:
>>
>> onlineapp.d(5): Error: template onlineapp.testFunction cannot deduce 
>> function from argument types !()(TestType!(int, float)), candidates are:
>> onlineapp.d(10):        onlineapp.testFunction(T, Q)(TestAlias!(T, Q) 
>> arg)
> 
> Yes, this example shows exactly the intention. Among other things, the DIP
> proposes that we should not have an error here.

I replied with this so that you had feedback for improving the DIP if 
other people find it hard to understand.


More information about the Digitalmars-d mailing list