Do you have an example of using it in C or C++?
For an example of how this plays out, I had some code:
let x = y + z;
I wasn't sure what y was, so I was able to let x = dbg!(y) + z;
this is much easier to insert into (and remove from) existing code. Plus, you don't need to write the formatting code.Basically, what you posted is in the same genre of thing, but is very different in a lot of meaningful ways.
let c = dbg!(dbg!(a) + dbg!(b));
one time... #include <iostream>
#include <string>
template<typename T>
T print_dbg(T val, std::string exp, std::string file, int line)
{
std::cerr << exp << " = " << val << " @ " << file << ":" << line << "\n";
return val;
}
#define dbg(x) print_dbg(x,#x,__FILE__,__LINE__) double c = dbg(dbg(a) + dbg(b));
gives a = 1 @ debug.cxx:16
b = 2 @ debug.cxx:16
dbg(a) + dbg(b) = 3 @ debug.cxx:16
which has extra dbg()s on the third line.If I could I would probably want to write
double dbg(c) = dbg(a) + dbg(b);
but that of course doesn't work.