First working code:
#include <iostream>
// NOTE: requires compiler which has __PRETTY_FUNCTION__, like gcc or clang
#define DUMP(v) std::cerr << __PRETTY_FUNCTION__ << ':' << __LINE__ << ':' << #v << "='" << (v) << "'\n"
int main(int argc) {
DUMP(argc);
DUMP(argc+1);
return 0;
}
which gives stderr output (gcc):
int main(int):8:argc='1'
int main(int):9:argc+1='2'
Now I'd like to have variadic macro with any number of arguments, so for example
DUMP(argc, argc+1);
would work, with output like:
int main(int):8:argc='1',argc+1='2'
But I could not yet come up with a nice solution. Is this even possible with a macro? If not, how about templates, or combination of macros and templates? C++11 and Boost are ok if needed, and solution can be gcc-specific if there's no standard way. Looking for actual code, which makes the variadic DUMP work like described above, or at least show equivalent info.