cannot use local f as parameter to non-global template

Paul Backus snarwin at gmail.com
Mon Dec 10 17:03:36 UTC 2018


On Monday, 10 December 2018 at 16:15:36 UTC, aliak wrote:
>
> 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?

Holder!f is a type, not a delegate, so passing it as a parameter 
to a non-global template is fine. Issue 5710 only applies to 
delegates passed directly as parameters.

Trying to reason about the "number of contexts" required is a 
waste of time. There's no logical, principled reason why one 
works and the other doesn't. It's purely an artifact of details 
in the compiler implementation.


More information about the Digitalmars-d-learn mailing list