Convenient debug printing

Olivier FAURE couteaubleu at gmail.com
Sat Feb 2 10:42:27 UTC 2019


On Saturday, 2 February 2019 at 00:06:58 UTC, Rubn wrote:
> import std.stdio;
>
> void dbg(alias a)(string file = __FILE__, int line = __LINE__) {
> 	writeln( file, "(", line, "): ", __traits(identifier, a), " = 
> ", a );
> }
>
> int value = 10;
> dbg!value;      // filename.d(12): value = 10

I did think it was weird that a similar result couldn't be 
produced using __FILE__ and __LINE__, given that even C++ has 
them.

Look like something that could be added to std.stdio.

Only problem:

     dbg!(2 + 1); // Prints "a = 3"

(could be mitigated by naming the alias "_")


More information about the Digitalmars-d mailing list