Can someone explain the meaning of C++ code

Revision en1, by Siriuslight, 2018-11-15 11:47:10

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

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Siriuslight 2018-11-15 11:47:10 650 Initial revision (published)