cannot use local f as parameter to non-global template

aliak something at something.com
Mon Dec 10 16:15:36 UTC 2018


On Saturday, 8 December 2018 at 14:21:01 UTC, Paul Backus wrote:
> On Saturday, 8 December 2018 at 09:57:29 UTC, aliak wrote:
>> This compiles fine. However, if I change the match template to:
>>
>> template match(handlers...) {
>>     auto match(alias f)(Holder!f holder) {
>>         return handlers[0](holder);
>>     }
>> }
>>
>> Notice the template parameter of the eponymous match is an 
>> alias now, and the function parameter is typed as a Holder.
>
> The "de-sugared" version of your second `match` function looks 
> like this:
>
> template match(handlers...) {
>     template match(alias f) {
>         auto match(Holder!f holder) {
>             return handlers[0](holder);
>         }
>     }
> }
>
> Notice the second template nested inside the first. That's the 
> "non-gloal template" the error is complaining about.

Ah, that's a good way of breaking it down. But ok, so then the 
other version would be lowered to:

template match(handlers...) {
     template match(T) {
         auto match(T holder) {
             return handlers[0](holder);
         }
     }
}

So now the second template is accessing a T, which is actually a 
Holder!f right? But doing that makes it "work". Even though the 
number of "contexts" needed to execute "handlers[0](holder)" is 
the same, right?


More information about the Digitalmars-d-learn mailing list