Suggestion for a new trait: __traits(getCaptures,...)
Paul Backus
snarwin at gmail.com
Tue Oct 22 16:42:36 UTC 2019
On Tuesday, 22 October 2019 at 14:26:49 UTC, Zoadian wrote:
> Example how i would imagine it:
> ```
> struct S{ int b; }
> int a;
> S s;
>
> auto fun = (){ return a + s.b; }
>
> alias vars = __traits(getCaptures, fun);
>
> assert_alias(vars[0] == a, vars[1] == s.b);
> ```
Rather than a new `__traits`, it would also suffice to add a
`.captures` property to delegates. Then we could write the
following:
int a;
auto fun = () { return a; };
assert(__traits(isSame, a, fun.captures[0]));
More information about the Digitalmars-d
mailing list