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

rikki cattermole rikki at cattermole.co.nz
Thu Jan 18 02:55:27 UTC 2018


On 17/01/2018 11:13 PM, Timothee Cour wrote:
> 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
> }
> 
> ```

__ARG_NAMES__ would be better.
Otherwise, DIP please!



More information about the Digitalmars-d mailing list