digitalmars.D.learn - Debug function / macro
- ag (4/4) Feb 03 2020 Does D have a debugging helper function or macro similar to this
- Paul Backus (17/21) Feb 03 2020 Here's one way you could do it:
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?
Feb 03 2020
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")); }
Feb 03 2020