From 36cec9a5cc8e2eddea8d192991310bc813901499 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 5 Oct 2021 05:01:05 +0300 Subject: [PATCH 1/3] Handle references to functions --- include/boost/core/type_name.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/boost/core/type_name.hpp b/include/boost/core/type_name.hpp index 9a82dd3..33e717f 100644 --- a/include/boost/core/type_name.hpp +++ b/include/boost/core/type_name.hpp @@ -332,6 +332,22 @@ template std::string type_name( tn_identity ) #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +// function references + +template std::string type_name( tn_identity ) +{ + return type_name( tn_identity() ) + "(&)(" + tn_add_each() + ')'; +} + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +template std::string type_name( tn_identity ) +{ + return type_name( tn_identity() ) + "(&&)(" + tn_add_each() + ')'; +} + +#endif + // function pointers template std::string type_name( tn_identity ) From 01bd23df5d30801deea2c16c30c3b95a6a6c89f0 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 5 Oct 2021 05:04:56 +0300 Subject: [PATCH 2/3] Add tests for function types --- test/type_name_test.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/type_name_test.cpp b/test/type_name_test.cpp index 6ab08f5..52a74a5 100644 --- a/test/type_name_test.cpp +++ b/test/type_name_test.cpp @@ -105,6 +105,18 @@ int main() TEST(void*); TEST(void const* volatile*); + TEST(void()); + TEST(int(float, A, B*)); + + TEST(void(*)()); + TEST(void(&)()); + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + + TEST(void(&&)()); + +#endif + TEST(A[]); TEST(A const[]); TEST(A volatile[]); From b93317815c7b62551e34e13253008d2d56817148 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 5 Oct 2021 05:30:37 +0300 Subject: [PATCH 3/3] Apply msvc-12.0 (and below) workarounds --- include/boost/core/type_name.hpp | 25 ++++++++++++++++++++++--- test/type_name_test.cpp | 3 +++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/boost/core/type_name.hpp b/include/boost/core/type_name.hpp index 33e717f..dfdedd3 100644 --- a/include/boost/core/type_name.hpp +++ b/include/boost/core/type_name.hpp @@ -14,6 +14,7 @@ // https://www.boost.org/LICENSE_1_0.txt #include +#include #include #include #include @@ -73,6 +74,24 @@ template struct tn_is_reference #endif +// tn_remove_const + +template struct tn_remove_const +{ + typedef T type; +}; + +template struct tn_remove_const +{ + typedef T type; +}; + +// tn_is_function (also catches references but that's OK) + +template::type> struct tn_is_function: core::is_same +{ +}; + #if !defined(BOOST_NO_TYPEID) // typeid_name @@ -261,21 +280,21 @@ template std::string type_name( tn_identity ) #else template -typename tn_enable_if::value, std::string>::type +typename tn_enable_if::value, std::string>::type type_name( tn_identity ) { return type_name( tn_identity() ) + " const"; } template -typename tn_enable_if::value, std::string>::type +typename tn_enable_if::value, std::string>::type type_name( tn_identity ) { return type_name( tn_identity() ) + " volatile"; } template -typename tn_enable_if::value, std::string>::type +typename tn_enable_if::value, std::string>::type type_name( tn_identity ) { return type_name( tn_identity() ) + " const volatile"; diff --git a/test/type_name_test.cpp b/test/type_name_test.cpp index 52a74a5..b3439c1 100644 --- a/test/type_name_test.cpp +++ b/test/type_name_test.cpp @@ -105,6 +105,8 @@ int main() TEST(void*); TEST(void const* volatile*); +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + TEST(void()); TEST(int(float, A, B*)); @@ -115,6 +117,7 @@ int main() TEST(void(&&)()); +#endif #endif TEST(A[]);