Created
December 20, 2019 19:58
-
-
Save jfalcou/2da943d75737294620cf35764a0950fa to your computer and use it in GitHub Desktop.
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
#include <string_view> | |
#include <iostream> | |
template<typename T> struct name_of_ | |
{ | |
static constexpr auto value() noexcept | |
{ | |
#if defined(_MSC_VER ) | |
std::string_view data(__FUNCSIG__); | |
auto i = data.find('<') + 1, | |
j = data.find(">::value"); | |
return data.substr(i, j - i); | |
#else | |
std::string_view data(__PRETTY_FUNCTION__); | |
auto i = data.find('=') + 2, | |
j = data.find_last_of(']'); | |
return data.substr(i, j - i); | |
#endif | |
} | |
}; | |
template<typename T> | |
inline constexpr auto const name_of = name_of_<T>::value(); | |
int main() | |
{ | |
auto x = name_of<std::string>; | |
std::cout << x << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment