May 17, 2018
On Monday, 19 September 2016 at 22:59:53 UTC, Jonathan Marler wrote:
> On Monday, 19 September 2016 at 22:17:34 UTC, Mathias Lang wrote:
>> 2016-09-19 23:18 GMT+02:00 Jonathan Marler via Digitalmars-d < digitalmars-d@puremagic.com>:
>>
>>>[...]
>>
>> 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`.
>
> Good example, thanks for the information.

Maybe the compiler can do more works to make the code more readable. Here are my examples:

template EventHandler(T=Object)
{
   alias EventHandler = void delegate(T sender);
}


void test01(EventHandler handler) // Error
{
  // It's what I want. However, it doesn't work.
}

void test02(EventHandler!() handler)
{
  // It works. Howerve, it ...
}

void test03()(EventHandler handler)
{
  // It works too. Howerve, it ...
}

void test04(EventHandler!string handler)
{
  // It's OK.
}



May 17, 2018
On Thursday, 17 May 2018 at 08:37:01 UTC, Heromyth wrote:
> On Monday, 19 September 2016 at 22:59:53 UTC, Jonathan Marler wrote:
>> On Monday, 19 September 2016 at 22:17:34 UTC, Mathias Lang wrote:
>>> [...]
>>
>> Good example, thanks for the information.
>
> Maybe the compiler can do more works to make the code more readable. Here are my examples:
>
> template EventHandler(T=Object)
> {
>    alias EventHandler = void delegate(T sender);
> }
>
>
> void test01(EventHandler handler) // Error
> {
>   // It's what I want. However, it doesn't work.
> }
>
> void test02(EventHandler!() handler)
> {
>   // It works. Howerve, it ...
> }
>
> void test03()(EventHandler handler)
> {
>   // It works too. Howerve, it ...
> }
>
> void test04(EventHandler!string handler)
> {
>   // It's OK.
> }


If you want, take a look at dtemplate.d in the compiler source. :)
I would advise to do this when well rested and motivated.
1 2
Next ›   Last »