using __traits to get line number of a member
Stanislav Blinov
stanislav.blinov at gmail.com
Sat Nov 13 17:22:16 UTC 2021
On Saturday, 13 November 2021 at 08:04:56 UTC, forkit wrote:
> int i;
> foreach(m; __traits(allMembers, mixin(__MODULE__)))
> // ...
> __traits(getLocation, mixin(m))[1]);
What you really should be doing is this:
```d
static import mod = mixin(__MODULE__);
foreach (i, name; __traits(allMembers, mod))
{
// ...
__traits(getLocation, __traits(getMember, mod, i));
// ...
}
```
Otherwise you might run into name conflicts, and get location of
a wrong symbol.
Also if you really want to be generic you should couple it with
`__traits(getOverloads)`, like the docs for getLocation suggest.
More information about the Digitalmars-d-learn
mailing list