non-global template fix POC WIP
Suleyman
sahmi.soulaimane at gmail.com
Tue Jan 22 22:26:14 UTC 2019
Hello everyone.
I started working on a fix for the non-global template issue.
Progress at https://github.com/dlang/dmd/pull/9282
currently the following POC works:
```
struct S
{
int m;
auto add(alias a)(int b)
{
return a + m + b;
}
auto exec(alias f)()
{
f(m);
}
}
void main()
{
int a = 4;
auto o = S(3);
assert(o.add!a(2) == 4+3+2);
auto dg = &o.add!a;
assert(dg(7) == 4+3+7);
int b;
auto bSetter(int i) { b = i; }
o.exec!bSetter();
assert(b == 3);
/* S.add instantiated to:
auto add(int b)
{
return main.a + main.o.m + b;
}
thus only requires the frame pointer of `main`
*/
}
```
The strategy is to access the `this` variable through the frame
pointer of the caller.
More information about the Digitalmars-d
mailing list