Skip to content

Instantly share code, notes, and snippets.

@ArnCarveris
Created November 14, 2019 22:14
Show Gist options
  • Save ArnCarveris/056068e3f2f1612c1df7418de8ce2ab7 to your computer and use it in GitHub Desktop.
Save ArnCarveris/056068e3f2f1612c1df7418de8ce2ab7 to your computer and use it in GitHub Desktop.
//@Innokentiy-Alaytsev - https://github.com/Manu343726/ctti
//@Innokentiy-Alaytsev - There is an example of constexpr thing @dBagrat posted recently
template< typename T >
static constexpr auto TypeName()
{
#if defined( _MSC_VER )
constexpr std::string_view funcName = __FUNCSIG__;
#else
constexpr std::string_view funcName = __PRETTY_FUNCTION__;
#endif
constexpr auto begin = funcName.find_first_of( '<' ) + 1;
constexpr auto end = funcName.find_last_of( '>' );
const std::string_view name = funcName.substr( begin, end - begin );
if( const auto spacePos = name.find_first_of( " " ); spacePos != std::string_view::npos )
return name.substr( spacePos + 1, name.size() - spacePos - 1 );
else
return name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment