This is the same question as Is it possible to print a variable's type in standard C++? but I don't want RTTI. I'm writing code with expression templates (e.g. Eigen), which means the types of my variables can be really involved and that I don't know the actual types. However, the compiler knows the types and can tell me when something goes wrong:
error: ‘const struct Eigen::EigenBase<Eigen::Matrix<double, 1, 1, 0, 1, 1> >’ ...
Is there any way I can convert a variable name to a string with the (static) type name so that I could debug the program without breaking it? E.g.
int a;
M b;
cout << TYPEOF(a) << endl << TYPEOF(b) << endl;
would print
int
const struct Eigen::EigenBase<Eigen::Matrix<double, 1, 1, 0, 1, 1> >’