I\'d like to make a debug logging function with the same parameters as printf. But one that can be removed by the pre-processor during optimized builds.
Not exactly what's asked in the question . But this code will be helpful for debugging purposes , it will print each variable's value along with it's name . This is completely type independent and supports variable number of arguments. And can even display values of STL's nicely , given that you overload output operator for them
#define show(args...) describe(#args,args);
template
void describe(string var_name,T value)
{
clog<
void describe(string var_names,T value,Args... args)
{
string::size_type pos = var_names.find(',');
string name = var_names.substr(0,pos);
var_names = var_names.substr(pos+1);
clog<
Sample Use :
int main()
{
string a;
int b;
double c;
a="string here";
b = 7;
c= 3.14;
show(a,b,c);
}
Output :
a = string here | b = 7 | c = 3.14