Thread overview
Passing nested template function
Aug 10, 2019
Prateek Nayak
Aug 10, 2019
Alex
Aug 10, 2019
aliak
August 10, 2019
A nested function can be passed to another function evident from this example: https://run.dlang.io/is/6waRkB

However if the nested function is a template function, it raises an error
https://run.dlang.io/is/PQhkwl
The error being: cannot get frame pointer to the nested function

Is there a way to pass a nested template function to a function declared outside the outer function scope?
August 10, 2019
On Saturday, 10 August 2019 at 17:45:43 UTC, Prateek Nayak wrote:
> A nested function can be passed to another function evident from this example: https://run.dlang.io/is/6waRkB
>
> However if the nested function is a template function, it raises an error
> https://run.dlang.io/is/PQhkwl
> The error being: cannot get frame pointer to the nested function
>
> Is there a way to pass a nested template function to a function declared outside the outer function scope?

The part I'm not sure about:
This is not possible: Before instantiation, the object does not exist, you cannot, therefore, pass its pointer, not to speak about the pointer of its frame.

However, how about this:
https://run.dlang.io/is/8drZRf
August 10, 2019
On Saturday, 10 August 2019 at 17:45:43 UTC, Prateek Nayak wrote:
> A nested function can be passed to another function evident from this example: https://run.dlang.io/is/6waRkB
>
> However if the nested function is a template function, it raises an error
> https://run.dlang.io/is/PQhkwl
> The error being: cannot get frame pointer to the nested function
>
> Is there a way to pass a nested template function to a function declared outside the outer function scope?

This looks like it could be a bug to me. If you explicitly instantiate the nested template and call dispatch like dispatch!(nested!0) then it works.

An alias template parameter can accept both a template and an instantiated template. I.e.

template X(T) {}
alias A = X; // ok
alias B = X!int; // ok

So it's unclear what should happen. At the least, the defaulted argument should be applied at the call site (Func(a)).

Note though that neither versions will work on ldc or gdc however. Because there's a bug [0] that has only been fixed in for dmd.

[0] https://github.com/dlang/dmd/pull/9282