Debug

Template 1

Reference: https://discuss.codechef.com/t/trace-__f-__va_args__-__va_args__/19200

#define TRACE // enable debug print

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

Template 2 (able to handle pair, vector)

Template 3 (able to handle pair, vector)

Last updated