Macros for debugging

Правка en1, от angelbeats, 2020-12-13 07:07:48
namespace std {
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#define tee(...) [](const auto& x){ cerr << "[" << #__VA_ARGS__ << "]: "; debug_out(x); return x; }(__VA_ARGS__)
#else
#define dbg(...) do {} while(0)
#define tee(...) (__VA_ARGS__)
#endif
}

The code above introduces tee, which simply prints one value and returns it.

g++ -DLOCAL -O2 --std=c++17 -o a a.cpp

Don't use c++11. Don't change std to other names. You can get rid of the std wrapper.

And here's the complete version, which handles tuple of any length, as well as complex.

Complete version
Теги macro, c++ 14

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский angelbeats 2020-12-13 07:07:48 2838 Initial revision (published)