mirror of
https://github.com/boostorg/core.git
synced 2025-07-31 13:27:29 +02:00
Refactor typeid_name<T> slighlty
This commit is contained in:
@ -22,6 +22,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstring>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||||
# include <string_view>
|
# include <string_view>
|
||||||
@ -41,54 +42,60 @@ template<class T> struct tn_identity
|
|||||||
typedef T type;
|
typedef T type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// tn_remove_prefix
|
||||||
|
|
||||||
|
inline bool tn_remove_prefix( std::string& str, char const* prefix )
|
||||||
|
{
|
||||||
|
std::size_t n = std::strlen( prefix );
|
||||||
|
|
||||||
|
if( str.substr( 0, n ) == prefix )
|
||||||
|
{
|
||||||
|
str = str.substr( n );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if !defined(BOOST_NO_TYPEID)
|
#if !defined(BOOST_NO_TYPEID)
|
||||||
|
|
||||||
// typeid_name
|
// typeid_name
|
||||||
|
|
||||||
template<class T> std::string typeid_name()
|
inline std::string fix_typeid_name( char const* n )
|
||||||
{
|
{
|
||||||
std::string r = boost::core::demangle( typeid(T).name() );
|
std::string r = boost::core::demangle( n );
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
|
||||||
if( r.substr( 0, 6 ) == "class " )
|
tn_remove_prefix( r, "class " );
|
||||||
{
|
tn_remove_prefix( r, "struct " );
|
||||||
r = r.substr( 6 );
|
tn_remove_prefix( r, "enum " );
|
||||||
}
|
|
||||||
|
|
||||||
if( r.substr( 0, 7 ) == "struct " )
|
|
||||||
{
|
|
||||||
r = r.substr( 7 );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( r.substr( 0, 5 ) == "enum " )
|
|
||||||
{
|
|
||||||
r = r.substr( 5 );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// libc++ inline namespace
|
// libc++ inline namespace
|
||||||
|
|
||||||
if( r.substr( 0, 10 ) == "std::__1::" )
|
if( tn_remove_prefix( r, "std::__1::" ) )
|
||||||
{
|
{
|
||||||
r = "std::" + r.substr( 10 );
|
r = "std::" + r;
|
||||||
}
|
}
|
||||||
|
|
||||||
// libstdc++ inline namespace
|
// libstdc++ inline namespace
|
||||||
|
|
||||||
if( r.substr( 0, 14 ) == "std::__cxx11::" )
|
if( tn_remove_prefix( r, "std::__cxx11::" ) )
|
||||||
{
|
{
|
||||||
r = "std::" + r.substr( 14 );
|
r = "std::" + r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(BOOST_MSVC) && BOOST_MSVC == 1600
|
#if defined(BOOST_MSVC) && BOOST_MSVC == 1600
|
||||||
|
|
||||||
// msvc-10.0 puts TR1 things in std::tr1
|
// msvc-10.0 puts TR1 things in std::tr1
|
||||||
|
|
||||||
if( r.substr( 0, 10 ) == "std::tr1::" )
|
if( tn_remove_prefix( r, "std::tr1::" ) )
|
||||||
{
|
{
|
||||||
r = "std::" + r.substr( 10 );
|
r = "std::" + r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -96,6 +103,11 @@ template<class T> std::string typeid_name()
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T> std::string typeid_name()
|
||||||
|
{
|
||||||
|
return fix_typeid_name( typeid(T).name() );
|
||||||
|
}
|
||||||
|
|
||||||
// template names
|
// template names
|
||||||
|
|
||||||
template<class T> std::string class_template_name()
|
template<class T> std::string class_template_name()
|
||||||
|
Reference in New Issue
Block a user