jeudi 9 janvier 2020

Alternatives to stringifying the variable name in C++11

In my code, I have repeatedly this expression:

T foo;
do_sth(foo, "foo");

I am considering stringifying the variable name, like this:

#define VARNAME(Var) (#Var)

void do_sth_new(T foo) { do_sth(foo, VARNAME(foo)); };

T foo;
do_sth_new(foo);

Is it good practice? Is there any better alternative in C++11?

Aucun commentaire:

Enregistrer un commentaire