Created
December 14, 2020 10:01
-
-
Save michael-martinez/e3f47db71915219807926dd0e39bdae5 to your computer and use it in GitHub Desktop.
C++ Type Inspector for C++17
This file contains hidden or 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> | |
template <typename T> | |
constexpr auto type_name() noexcept { | |
std::string_view name = "Error: unsupported compiler", prefix, suffix; | |
#ifdef __clang__ | |
name = __PRETTY_FUNCTION__; | |
prefix = "auto type_name() [T = "; | |
suffix = "]"; | |
#elif defined(__GNUC__) | |
name = __PRETTY_FUNCTION__; | |
prefix = "constexpr auto type_name() [with T = "; | |
suffix = "]"; | |
#elif defined(_MSC_VER) | |
name = __FUNCSIG__; | |
prefix = "auto __cdecl type_name<"; | |
suffix = ">(void) noexcept"; | |
#endif | |
name.remove_prefix(prefix.size()); | |
name.remove_suffix(suffix.size()); | |
return name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment