Created
September 8, 2021 03:05
-
-
Save jeremy-rifkin/592ca33c4bf4aac078eae02160a2712e to your computer and use it in GitHub Desktop.
Revisions
-
jeremy-rifkin created this gist
Sep 8, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ template<class T> constexpr std::string_view type_name() { // clang: std::string_view ns::type_name() [T = int] // gcc: constexpr std::string_view ns::type_name() [with T = int; std::string_view = std::basic_string_view<char>] // msvc: const char *__cdecl ns::type_name<int>(void) auto substring_bounded_by = [](std::string_view sig, std::string_view l, std::string_view r) { assert(sig.find(l) != std::string_view::npos); assert(sig.rfind(r) != std::string_view::npos); assert(sig.find(l) < sig.rfind(r)); auto i = sig.find(l) + l.length(); return sig.substr(i, sig.rfind(r) - i); }; #if defined(__clang__) return substring_bounded_by(__PRETTY_FUNCTION__, "[T = ", "]"); #elif defined(__GNUC__) || defined(__GNUG__) return substring_bounded_by(__PRETTY_FUNCTION__, "[with T = ", "; std::string_view = "); #elif defined(_MSC_VER) return substring_bounded_by(__FUNCSIG__, "type_name<", ">(void)"); #else // TODO: ? return __PRETTY_FUNCTION__; #endif }