On Sunday, 2 August 2020 at 16:31:50 UTC, Adam D. Ruppe wrote:
On Sunday, 2 August 2020 at 16:05:07 UTC, Ronoroa wrote:
That doesn't seem to stringize the args part like in #__VA_ARGS__

oh yeah i missed that part.

D basically can't do that exactly, but if you pass the args as template things directly you can do this:

---
void main(string[] args) {
        int a;
        int b = 34;
        dbg!(a, b); // notice the !
}

void dbg(Args...)(size_t line = __LINE__) {
        import std.stdio;

        write("#", line, ": ");
        foreach(idx, alias arg; Args) {
                if(idx) write(", ");
                write(arg.stringof, " = ", arg);
        }
        writeln();
}
---

#4: a = 0, b = 34


Or reformat the output however you want.

That's so much nicer than the C++ macro. Thanks a lot!


Reply via email to