Re:Show HN: Nameof Operator for Modern C++
by neargye on Monday March 25, 2019 @03:58AM
(#19480914)
In our project, NAMEOF_TYPE and NAMEOF almost do not add time relative to the entire project.
But NAMEOF_ENUM can add a couple of seconds to large enums.
Re:Show HN: Nameof Operator for Modern C++
by gpderetta on Sunday March 24, 2019 @03:23PM
(#19478218)
It probably uses stringification under the hood, but then relies on constexpr to "canonicalize" the name (removing everything before the dot, template parameters etc).
Re:Show HN: Nameof Operator for Modern C++
by Someone on Sunday March 24, 2019 @04:07PM
(#19478465)
From cursory reading, it seems it doesn’t, at all. It uses compiler-specific predefined values __PRETTY_FUNCTION__ (gcc, clang) or __FUNCSIG__ (MS Visual C++), and doesn’t work on other compilers.
It also has to do work to extract the function name from the char arrays/C strings that those macros expand to.
Re:Show HN: Nameof Operator for Modern C++
by anon4242 on Sunday March 24, 2019 @04:54PM
(#19478708)
Actually, __FUNCTION__ won't work as it only expands to the name of the function, not any templates or arguments.
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.
I do wonder how much this would impact compile-times if used moderately in a large code-base.
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.