Siriuslight's blog

By Siriuslight, history, 6 years ago, In English

I have seen these lines in codes of various people. People use it for debugging. Can someone please explain how it works?

#define TRACE
#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
  • Vote: I like it
  • +1
  • Vote: I do not like it

| Write comment?