Proposal for new compiler built-ins: __CTX__ and __CONTEXT__

ryuukk_ ryuukk.dev at gmail.com
Thu Jun 22 19:49:31 UTC 2023


I like the idea, i have some code in my projects where i use 
__FILE__ and __LINE__, would make my functions much shorters

However, i feel like this is asking for something else

Like your example:

```D
void infoStack(string msg, __CTX__ ctx = __CONTEXT__) {
     writefln("%s(%s): %s", ctx.file, ctx.line, msg);
}
```

This is redundant, you'd never pass a __CTX__ yourself, i reusing 
traits as suggested trait makes more sense

Never been a fan of uglyf-ing function arguments that one never 
gonna use themselves


```D
void infoStack(string msg) {
     enum file = __traits(context, calling_file);
     enum line = __traits(context, calling_line);
     writefln("%s(%s): %s", file, line, msg);
}
```



More information about the Digitalmars-d mailing list