How to get the location (file, line) of UDA without parens?

Andrey Zherikov andrey.zherikov at gmail.com
Sun Nov 14 05:12:58 UTC 2021


Here is my code:
```d
struct L
{
     string file;
     size_t line;
}

auto W(string f = __FILE__,size_t l= __LINE__)()
{
     return L(f,l);
}

struct A
{
   @W       // (1): line# 16
   {
     int a;
     int b;
   }
   @W()     // (2): line# 21
   {
     int c;
     int d;
   }
}

void main()
{
     pragma(msg, __traits(getAttributes, A.a)); // tuple(W(string 
f = __FILE__, ulong l = __LINE__)())
     pragma(msg, __traits(getAttributes, A.b)); // tuple(W(string 
f = __FILE__, ulong l = __LINE__)())
     pragma(msg, __traits(getAttributes, A.c)); // 
tuple(L("app.d", 21LU))
     pragma(msg, __traits(getAttributes, A.d)); // 
tuple(L("app.d", 21LU))
}
```

`W()` (2) works as expected but is it possible to achieve the 
same without parenthesis so `getAttributes` trait returns 
`tuple(L("app.d", 16LU))` for (1)?


More information about the Digitalmars-d-learn mailing list