Created
May 14, 2019 05:02
-
-
Save halfelf/801df7fa7d0f1fb6a1c16a7b405b0021 to your computer and use it in GitHub Desktop.
Get C++ type name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T> | |
constexpr std::string_view type_name() { | |
#ifdef __clang__ | |
std::string_view p = __PRETTY_FUNCTION__; | |
return std::string_view(p.data() + 34, p.size() - 34 - 1); | |
#elif defined(__GNUC__) | |
std::string_view p = __PRETTY_FUNCTION__; | |
# if __cplusplus < 201402 | |
return std::string_view(p.data() + 36, p.size() - 36 - 1); | |
# else | |
return std::string_view(p.data() + 49, p.find(';', 49) - 49); | |
# endif | |
#elif defined(_MSC_VER) | |
std::string_view p = __FUNCSIG__; | |
return std::string_view(p.data() + 84, p.size() - 84 - 7); | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment