1
0
forked from boostorg/core

Merge branch 'feature/type-name' into feature/lwt-type-name

This commit is contained in:
Peter Dimov
2021-10-05 05:31:09 +03:00
2 changed files with 53 additions and 3 deletions

View File

@ -14,6 +14,7 @@
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/core/demangle.hpp>
#include <boost/core/is_same.hpp>
#include <boost/config.hpp>
#include <string>
#include <functional>
@ -73,6 +74,24 @@ template<class T> struct tn_is_reference<T&&>
#endif
// tn_remove_const
template<class T> struct tn_remove_const
{
typedef T type;
};
template<class T> struct tn_remove_const<T const>
{
typedef T type;
};
// tn_is_function (also catches references but that's OK)
template<class T, class U = typename tn_remove_const<T>::type> struct tn_is_function: core::is_same<U, U const>
{
};
#if !defined(BOOST_NO_TYPEID)
// typeid_name
@ -261,21 +280,21 @@ template<class T> std::string type_name( tn_identity<T const volatile> )
#else
template<class T>
typename tn_enable_if<!tn_is_reference<T>::value, std::string>::type
typename tn_enable_if<!tn_is_function<T>::value, std::string>::type
type_name( tn_identity<T const> )
{
return type_name( tn_identity<T>() ) + " const";
}
template<class T>
typename tn_enable_if<!tn_is_reference<T>::value, std::string>::type
typename tn_enable_if<!tn_is_function<T>::value, std::string>::type
type_name( tn_identity<T volatile> )
{
return type_name( tn_identity<T>() ) + " volatile";
}
template<class T>
typename tn_enable_if<!tn_is_reference<T>::value, std::string>::type
typename tn_enable_if<!tn_is_function<T>::value, std::string>::type
type_name( tn_identity<T const volatile> )
{
return type_name( tn_identity<T>() ) + " const volatile";
@ -332,6 +351,22 @@ template<class T> std::string type_name( tn_identity<T*> )
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
// function references
template<class R, class... A> std::string type_name( tn_identity<R(&)(A...)> )
{
return type_name( tn_identity<R>() ) + "(&)(" + tn_add_each<A...>() + ')';
}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
template<class R, class... A> std::string type_name( tn_identity<R(&&)(A...)> )
{
return type_name( tn_identity<R>() ) + "(&&)(" + tn_add_each<A...>() + ')';
}
#endif
// function pointers
template<class R, class... A> std::string type_name( tn_identity<R(*)(A...)> )

View File

@ -105,6 +105,21 @@ int main()
TEST(void*);
TEST(void const* volatile*);
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
TEST(void());
TEST(int(float, A, B*));
TEST(void(*)());
TEST(void(&)());
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
TEST(void(&&)());
#endif
#endif
TEST(A[]);
TEST(A const[]);
TEST(A volatile[]);