Is there any way, using c++11, to get the name of a variable that is a (possibly static) constexpr.
For example:
struct Foo{
int x, y, z;
};
constexpr Foo PrintMe = { 1, 2, 3};
I would like to get a string "PrintMe" somehow.
I know that I can use a macro like:
#define NAME_OF( v ) #v
and call
std::cout << NAME_OF(PrintMe) << std::endl;
which will print
PrintMe
Is there a way to get the following print the same?
Foo a = PrintMe;
std::cout << Magic(a) << std::endl;
EDIT:
I am not looking for some magic solution which will make the call to Magic(a)
work. I understand that doing something to accommodate what I want will require defining some macros or templates.
Like enums can be printed in some sort of way (How to convert an enum type variable to a string?