On Monday, 3 February 2020 at 22:07:13 UTC, ag wrote:
Does D have a debugging helper function or macro similar to
this one in Rust? (https://doc.rust-lang.org/std/macro.dbg.html)
If not, how would one implement this / how difficult would it
be to implement?
Here's one way you could do it:
string debugPrint(string expr, string file = __FILE__, size_t
line = __LINE__)
{
import std.format;
return q{() {
import std.stdio: writeln;
debug writeln(`[%2$s:%3$d] %1$s`, " = ", %1$s);
}();}.format(expr, file, line);
}
void main()
{
int x = 123;
int y = 456;
mixin(debugPrint("x + y"));
}