3 ms·
After I saw this in Rust, I had to implement it in C++: #include <iostream> #include <string> template<typename T> T print_dbg(T val, std::str
by CJefferson 6y ago
After I saw this in Rust, I had to implement it in C++:
#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__)
- petschge 6y agoClose. Applying that to 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.