Show HN: Nameof Operator for Modern C++
github.com
github.com
I do wonder how much this would impact compile-times if used moderately in a large code-base.
#define STRINGIZE_DETAIL(x) #x
#define STRINGIZE(x) STRINGIZE_DETAIL(x)It also has to do work to extract the function name from the char arrays/C strings that those macros expand to.
Reading answers to https://stackoverflow.com/questions/4384765/whats-the-differ..., it seems it would have been easier to use the __FUNCTION__ in gcc, but I’m not familiar with that (or the other predefined values) at all, so who knows?
It's actually a pretty clever way to automagically deduce not only names of variables but also of enums :). Too bad it's most likely not maintainable in the long run as compilers probably change what their __PRETTY_FUNCTION__ (or equivalent) macros expand to in new versions.