__ARGS__ : allow access to (stringified) arguments, as C's `#arg` macro

Timothee Cour thelastmammoth at gmail.com
Wed Jan 17 23:13:30 UTC 2018


I wrote something like that to mimic C's `#arg` preprocessor
(stringify argument) for debugging functions, eg:

```
// simplified here:
void log(string file=__FILE__, int line=__LINE__, T) (T a){
   enum arg_stringified=import(file)[line]; // more complex in practice
  writeln(arg_stringified, ":", a);
}
void main(){
  log(1+3); // prints: `1+3:4`
}
```

however: this slows down compilation a lot (in larger programs) and
has potentially complex logic  to deal with multiple arguments, and
UFCS, as we need to redo the job of the parser to get access to
individual elements stringified
we can avoid slowing down compilation time by passing pass file,line
at runtime and use readText, has the defect of not working if code was
compiled and source changed at a later time.

So I'd still like a solution that mimic's C's `#arg` preprocessor
https://gcc.gnu.org/onlinedocs/gcc-4.0.0/cpp/Stringification.html ;
it's sad that D is inferior to C in that respect.

what i would like instead is __ARGS__:
thus allowing:
```
void log(T...) (T a, string file=__FILE__, int line=__LINE__, string[]
arg_names=__ARGS__){
  writeln(file, ":", line, " ", zip(arg_names, a))); // or better formatting
}

```


More information about the Digitalmars-d mailing list