An existing macro gets variadic number of variables on my application.
I want, using this macro, to print these variables by name=value
format.
Here is a small example :
#define EXISTING_MACRO(...) < ??? >
int main()
int a = 0;
int b = 1;
int c = 2;
EXISTING_MACRO(a,b,c);
Output should be :
a=0, b=1, c=2
I've tried doing so by calling a variadic template function from within the macro, and I do succeed printing the variables values, but not the variables names. (#x
prints their addresses, and even if it didn't it would probably just show the method variable name, 'f'
) :
#define SHOW(a) std::cout << #a << "=" << (a)
template<typename TF>
void write_err_output(std::ostream& out, TF const& f) {
out << f << std::endl;
}
template<typename TF, typename ... TR>
void write_err_output(std::ostream& out, TF const& f, TR const& ... rest) {
out << SHOW(f) << " ";
write_err_output(out, rest...);
}