forked from boostorg/core
Merge branch 'feature/type-name' into feature/lwt-type-name
This commit is contained in:
@ -14,6 +14,7 @@
|
|||||||
// https://www.boost.org/LICENSE_1_0.txt
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
#include <boost/core/demangle.hpp>
|
#include <boost/core/demangle.hpp>
|
||||||
|
#include <boost/core/is_same.hpp>
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@ -73,6 +74,24 @@ template<class T> struct tn_is_reference<T&&>
|
|||||||
|
|
||||||
#endif
|
#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)
|
#if !defined(BOOST_NO_TYPEID)
|
||||||
|
|
||||||
// typeid_name
|
// typeid_name
|
||||||
@ -261,21 +280,21 @@ template<class T> std::string type_name( tn_identity<T const volatile> )
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
template<class T>
|
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> )
|
type_name( tn_identity<T const> )
|
||||||
{
|
{
|
||||||
return type_name( tn_identity<T>() ) + " const";
|
return type_name( tn_identity<T>() ) + " const";
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
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> )
|
type_name( tn_identity<T volatile> )
|
||||||
{
|
{
|
||||||
return type_name( tn_identity<T>() ) + " volatile";
|
return type_name( tn_identity<T>() ) + " volatile";
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
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> )
|
type_name( tn_identity<T const volatile> )
|
||||||
{
|
{
|
||||||
return 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)
|
#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
|
// function pointers
|
||||||
|
|
||||||
template<class R, class... A> std::string type_name( tn_identity<R(*)(A...)> )
|
template<class R, class... A> std::string type_name( tn_identity<R(*)(A...)> )
|
||||||
|
@ -105,6 +105,21 @@ int main()
|
|||||||
TEST(void*);
|
TEST(void*);
|
||||||
TEST(void const* volatile*);
|
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[]);
|
||||||
TEST(A const[]);
|
TEST(A const[]);
|
||||||
TEST(A volatile[]);
|
TEST(A volatile[]);
|
||||||
|
Reference in New Issue
Block a user