Default Template Instantiation

Mathias Lang via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 19 15:17:34 PDT 2016


2016-09-19 23:18 GMT+02:00 Jonathan Marler via Digitalmars-d <
digitalmars-d at puremagic.com>:

> On Monday, 19 September 2016 at 21:14:38 UTC, Stefan Koch wrote:
>
>> On Monday, 19 September 2016 at 21:09:37 UTC, Jonathan Marler wrote:
>>
>>>
>>> I don't know if I would call this a "destabalizing" language change
>>> though.  It should be backwards compatible with the existing semantics.  It
>>> adds an extra step to type deduction, but this would be the very last step
>>> of type deduction so it would not override any existing semantics.
>>>
>>
>> Consider void functionOrTemplate() {...} and functionOrTemplate(uint N =
>> 1)() {...}
>>
>
> Oh you're right, I didn't think that templates could share the same name
> as functions.  You can't do this with classes:
>
> class classOrTemplate { }
> class classOrTemplate(uint N=1) { }
>
> With this new information, yes this would be a "destabalizing" language
> change.  Thanks for the example.  I'm against this.
>

No you can't. The example is wrong, but Stefan is right.
Consider:

```
template Foo (T = string) { }

template TakesAlias(alias Sym) {}

alias TakesAlias!(Foo) Bar;
```

In this context, is `TakesAlias` instantiated with the template or the
template instantiation ?

It is essentially the same category of problems as when trying to use a
parameterless-functions, sometime you end up calling it because of the
optional parenthesis. Except that for functions we can use `&` or `typeof`.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20160920/1f826f27/attachment.html>


More information about the Digitalmars-d mailing list