diff --git a/include/boost/core/type_name.hpp b/include/boost/core/type_name.hpp index 5512c0c..8a118ad 100644 --- a/include/boost/core/type_name.hpp +++ b/include/boost/core/type_name.hpp @@ -31,7 +31,6 @@ namespace boost { namespace core { - namespace detail { @@ -42,65 +41,6 @@ template struct tn_identity typedef T type; }; -// tn_enable_if - -template struct tn_enable_if -{ -}; - -template struct tn_enable_if -{ - typedef T type; -}; - -// tn_is_reference - -template struct tn_is_reference -{ - static const bool value = false; -}; - -template struct tn_is_reference -{ - static const bool value = true; -}; - -#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - -template struct tn_is_reference -{ - static const bool value = true; -}; - -#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) - -#if defined(BOOST_MSVC) -# pragma warning(push) -# pragma warning(disable: 4180 4181) -#endif - -template::type> struct tn_is_function: core::is_same -{ -}; - -#if defined(BOOST_MSVC) -# pragma warning(pop) -#endif - #if !defined(BOOST_NO_TYPEID) // typeid_name @@ -160,28 +100,36 @@ template std::string typeid_name() template std::string class_template_name() { - std::string r = typeid_name(); +#if defined(BOOST_GCC) + + std::string r = typeid_name(); + +#else + + std::string r = typeid_name(); + +#endif return r.substr( 0, r.find( '<' ) ); } template std::string sequence_template_name() { - return class_template_name(); + return detail::class_template_name(); } template std::string set_template_name() { - return class_template_name(); + return detail::class_template_name(); } template std::string map_template_name() { - return class_template_name(); + return detail::class_template_name(); } template std::string array_template_name() { - return class_template_name(); + return detail::class_template_name(); } #else // #if !defined(BOOST_NO_TYPEID) @@ -237,14 +185,116 @@ inline std::string tn_to_string( std::size_t n ) # pragma warning( pop ) #endif -// tn_add_each +// tn_holder + +template struct tn_holder +{ + static std::string type_name( std::string const& suffix ) + { + return typeid_name() + suffix; + } +}; + +// integrals + +template<> struct tn_holder +{ + static std::string type_name( std::string const& suffix ) + { + return "unsigned" + suffix; + } +}; + +#if defined(_MSC_VER) + +template<> struct tn_holder +{ + static std::string type_name( std::string const& suffix ) + { + return "long long" + suffix; + } +}; + +template<> struct tn_holder +{ + static std::string type_name( std::string const& suffix ) + { + return "unsigned long long" + suffix; + } +}; + +#endif + +#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L + +template<> struct tn_holder +{ + static std::string type_name( std::string const& suffix ) + { + return "char8_t" + suffix; + } +}; + +#endif + +// cv + +template struct tn_holder +{ + static std::string type_name( std::string const& suffix ) + { + return tn_holder::type_name( " const" + suffix ); + } +}; + +template struct tn_holder +{ + static std::string type_name( std::string const& suffix ) + { + return tn_holder::type_name( " volatile" + suffix ); + } +}; + +template struct tn_holder +{ + static std::string type_name( std::string const& suffix ) + { + return tn_holder::type_name( " const volatile" + suffix ); + } +}; + +// refs + +template struct tn_holder +{ + static std::string type_name( std::string const& suffix ) + { + return tn_holder::type_name( "&" + suffix ); + } +}; + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +template struct tn_holder +{ + static std::string type_name( std::string const& suffix ) + { + return tn_holder::type_name( "&&" + suffix ); + } +}; + +#endif + +// function types #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +// tn_add_each + template int tn_add_each_impl( std::string& st ) { if( !st.empty() ) st += ", "; - st += type_name( tn_identity(), "" ); + st += tn_holder::type_name( "" ); return 0; } @@ -258,125 +308,9 @@ template std::string tn_add_each() return st; } -#endif - -// primary - -template std::string type_name( tn_identity, std::string const& suffix ) -{ - return typeid_name() + suffix; -} - -// integrals - -inline std::string type_name( tn_identity, std::string const& suffix ) -{ - return "unsigned" + suffix; -} - -#if defined(_MSC_VER) - -inline std::string type_name( tn_identity, std::string const& suffix ) -{ - return "long long" + suffix; -} - -inline std::string type_name( tn_identity, std::string const& suffix ) -{ - return "unsigned long long" + suffix; -} - -#endif - -#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L - -inline std::string type_name( tn_identity, std::string const& suffix ) -{ - return "char8_t" + suffix; -} - -#endif - -// cv - -#if !defined(BOOST_MSVC) || BOOST_MSVC >= 1900 - -template std::string type_name( tn_identity, std::string const& suffix ) -{ - return type_name( tn_identity(), " const" + suffix ); -} - -template std::string type_name( tn_identity, std::string const& suffix ) -{ - return type_name( tn_identity(), " volatile" + suffix ); -} - -template std::string type_name( tn_identity, std::string const& suffix ) -{ - return type_name( tn_identity(), " const volatile" + suffix ); -} - -#else - -template -typename tn_enable_if::value, std::string>::type -type_name( tn_identity, std::string const& suffix ) -{ - return type_name( tn_identity(), " const" + suffix ); -} - -template -typename tn_enable_if::value, std::string>::type -type_name( tn_identity, std::string const& suffix ) -{ - return type_name( tn_identity(), " volatile" + suffix ); -} - -template -typename tn_enable_if::value, std::string>::type -type_name( tn_identity, std::string const& suffix ) -{ - return type_name( tn_identity(), " const volatile" + suffix ); -} - -#endif - -// refs - -#if !defined(BOOST_MSVC) || BOOST_MSVC >= 1900 - -template std::string type_name( tn_identity, std::string const& suffix ) -{ - return type_name( tn_identity(), "&" + suffix ); -} - -#else - -template -typename tn_enable_if::value, std::string>::type -type_name( tn_identity, std::string const& suffix ) -{ - return type_name( tn_identity(), "&" + suffix ); -} - -#endif - -#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - -template std::string type_name( tn_identity, std::string const& suffix ) -{ - return type_name( tn_identity(), "&&" + suffix ); -} - -#endif - -// function types - -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) - template std::string function_type_name( tn_identity, std::string const& trailer, std::string const& suffix ) { - std::string r = type_name( tn_identity(), "" ); + std::string r = tn_holder::type_name( "" ); if( !suffix.empty() ) { @@ -400,135 +334,207 @@ template std::string function_type_name( tn_identity std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), "", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), "", suffix ); + } +}; #if !defined(BOOST_MSVC) || BOOST_MSVC >= 1900 -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " volatile", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " volatile", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const volatile", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const volatile", suffix ); + } +}; #endif #if !defined(BOOST_NO_CXX11_REF_QUALIFIERS) -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " &", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " &", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const &", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const &", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " volatile &", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " volatile &", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const volatile &", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const volatile &", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " &&", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " &&", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const &&", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const &&", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " volatile &&", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " volatile &&", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const volatile &&", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const volatile &&", suffix ); + } +}; #endif #if defined( __cpp_noexcept_function_type ) || defined( _NOEXCEPT_TYPES_SUPPORTED ) -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " noexcept", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " noexcept", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const noexcept", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const noexcept", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " volatile noexcept", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " volatile noexcept", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const volatile noexcept", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const volatile noexcept", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " & noexcept", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " & noexcept", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const & noexcept", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const & noexcept", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " volatile & noexcept", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " volatile & noexcept", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const volatile & noexcept", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const volatile & noexcept", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " && noexcept", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " && noexcept", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const && noexcept", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const && noexcept", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " volatile && noexcept", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " volatile && noexcept", suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const volatile && noexcept", suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const volatile && noexcept", suffix ); + } +}; #endif @@ -536,21 +542,24 @@ template std::string type_name( tn_identity std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return type_name( tn_identity(), "*" + suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return tn_holder::type_name( "*" + suffix ); + } +}; // arrays template std::pair array_prefix_suffix( tn_identity ) { - return std::pair( type_name( tn_identity(), "" ), "" ); + return std::pair( tn_holder::type_name( "" ), "" ); } template std::pair array_prefix_suffix( tn_identity ) { - std::pair r = array_prefix_suffix( tn_identity() ); + std::pair r = detail::array_prefix_suffix( tn_identity() ); r.second = '[' + tn_to_string( N ) + ']' + r.second; @@ -559,7 +568,7 @@ template std::pair array_prefi template std::string array_type_name( tn_identity, std::string const& suffix ) { - std::pair r = array_prefix_suffix( tn_identity() ); + std::pair r = detail::array_prefix_suffix( tn_identity() ); if( suffix.empty() ) { @@ -571,29 +580,41 @@ template std::string array_type_name( tn_identity, std::string con } } -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return array_type_name( tn_identity(), suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::array_type_name( tn_identity(), suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return array_type_name( tn_identity(), suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::array_type_name( tn_identity(), suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return array_type_name( tn_identity(), suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::array_type_name( tn_identity(), suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return array_type_name( tn_identity(), suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::array_type_name( tn_identity(), suffix ); + } +}; template std::string array_type_name( tn_identity, std::string const& suffix ) { - std::pair r = array_prefix_suffix( tn_identity() ); + std::pair r = detail::array_prefix_suffix( tn_identity() ); if( suffix.empty() ) { @@ -605,54 +626,81 @@ template std::string array_type_name( tn_identity, } } -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return array_type_name( tn_identity(), suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::array_type_name( tn_identity(), suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return array_type_name( tn_identity(), suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::array_type_name( tn_identity(), suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return array_type_name( tn_identity(), suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::array_type_name( tn_identity(), suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return array_type_name( tn_identity(), suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::array_type_name( tn_identity(), suffix ); + } +}; // pointers to members -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return type_name( tn_identity(), ' ' + type_name( tn_identity(), "" ) + "::*" + suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return tn_holder::type_name( ' ' + tn_holder::type_name( "" ) + "::*" + suffix ); + } +}; #if defined(BOOST_MSVC) && BOOST_MSVC < 1900 && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), "", ' ' + type_name( tn_identity(), "" ) + "::*" + suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), "", ' ' + tn_holder::type_name( "" ) + "::*" + suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const", ' ' + type_name( tn_identity(), "" ) + "::*" + suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const", ' ' + tn_holder::type_name( "" ) + "::*" + suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " volatile", ' ' + type_name( tn_identity(), "" ) + "::*" + suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " volatile", ' ' + tn_holder::type_name( "" ) + "::*" + suffix ); + } +}; -template std::string type_name( tn_identity, std::string const& suffix ) +template struct tn_holder { - return function_type_name( tn_identity(), " const volatile", ' ' + type_name( tn_identity(), "" ) + "::*" + suffix ); -} + static std::string type_name( std::string const& suffix ) + { + return detail::function_type_name( tn_identity(), " const volatile", ' ' + tn_holder::type_name( "" ) + "::*" + suffix ); + } +}; #endif @@ -660,108 +708,150 @@ template std::string type_name( tn_identity, std::string const& suffix ) +template<> struct tn_holder { - return "std::nullptr_t" + suffix; -} + static std::string type_name( std::string const& suffix ) + { + return "std::nullptr_t" + suffix; + } +}; #endif // strings -template class L, class Ch> std::string type_name( tn_identity< L, std::allocator > >, std::string const& suffix ) +template class L, class Ch> struct tn_holder< L, std::allocator > > { - std::string tn = sequence_template_name< L, std::allocator > >(); - return tn + '<' + type_name( tn_identity(), "" ) + '>' + suffix; -} + static std::string type_name( std::string const& suffix ) + { + std::string tn = sequence_template_name< L, std::allocator > >(); + return tn + '<' + tn_holder::type_name( "" ) + '>' + suffix; + } +}; -inline std::string type_name( tn_identity, std::string const& suffix ) +template<> struct tn_holder { - return "std::string" + suffix; -} + static std::string type_name( std::string const& suffix ) + { + return "std::string" + suffix; + } +}; -inline std::string type_name( tn_identity, std::string const& suffix ) +template<> struct tn_holder { - return "std::wstring" + suffix; -} + static std::string type_name( std::string const& suffix ) + { + return "std::wstring" + suffix; + } +}; #if !defined(BOOST_NO_CXX11_CHAR16_T) -inline std::string type_name( tn_identity, std::string const& suffix ) +template<> struct tn_holder { - return "std::u16string" + suffix; -} + static std::string type_name( std::string const& suffix ) + { + return "std::u16string" + suffix; + } +}; #endif #if !defined(BOOST_NO_CXX11_CHAR32_T) -inline std::string type_name( tn_identity, std::string const& suffix ) +template<> struct tn_holder { - return "std::u32string" + suffix; -} + static std::string type_name( std::string const& suffix ) + { + return "std::u32string" + suffix; + } +}; #endif #if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L -inline std::string type_name( tn_identity>, std::string const& suffix ) +template<> struct tn_holder< std::basic_string > { - return "std::u8string" + suffix; -} + static std::string type_name( std::string const& suffix ) + { + return "std::u8string" + suffix; + } +}; #endif // string views (et al) -template class L, class Ch> std::string type_name( tn_identity< L > >, std::string const& suffix ) +template class L, class Ch> struct tn_holder< L > > { - std::string tn = sequence_template_name< L > >(); - return tn + '<' + type_name( tn_identity(), "" ) + '>' + suffix; -} + static std::string type_name( std::string const& suffix ) + { + std::string tn = sequence_template_name< L > >(); + return tn + '<' + tn_holder::type_name( "" ) + '>' + suffix; + } +}; // needed for libstdc++ -inline std::string type_name( tn_identity, std::string const& suffix ) +template<> struct tn_holder { - return "std::ostream" + suffix; -} + static std::string type_name( std::string const& suffix ) + { + return "std::ostream" + suffix; + } +}; #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) -inline std::string type_name( tn_identity, std::string const& suffix ) +template<> struct tn_holder { - return "std::string_view" + suffix; -} + static std::string type_name( std::string const& suffix ) + { + return "std::string_view" + suffix; + } +}; -inline std::string type_name( tn_identity, std::string const& suffix ) +template<> struct tn_holder { - return "std::wstring_view" + suffix; -} + static std::string type_name( std::string const& suffix ) + { + return "std::wstring_view" + suffix; + } +}; #if !defined(BOOST_NO_CXX11_CHAR16_T) -inline std::string type_name( tn_identity, std::string const& suffix ) +template<> struct tn_holder { - return "std::u16string_view" + suffix; -} + static std::string type_name( std::string const& suffix ) + { + return "std::u16string_view" + suffix; + } +}; #endif #if !defined(BOOST_NO_CXX11_CHAR32_T) -inline std::string type_name( tn_identity, std::string const& suffix ) +template<> struct tn_holder { - return "std::u32string_view" + suffix; -} + static std::string type_name( std::string const& suffix ) + { + return "std::u32string_view" + suffix; + } +}; #endif #if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L -inline std::string type_name( tn_identity>, std::string const& suffix ) +template<> struct tn_holder< std::basic_string_view > { - return "std::u8string_view" + suffix; -} + static std::string type_name( std::string const& suffix ) + { + return "std::u8string_view" + suffix; + } +}; #endif @@ -771,87 +861,114 @@ inline std::string type_name( tn_identity>, std: #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) -template class L, class... T> std::string type_name( tn_identity< L >, std::string const& suffix ) +template class L, class... T> struct tn_holder< L > { - std::string tn = class_template_name< L >(); - std::string st = tn_add_each(); + static std::string type_name( std::string const& suffix ) + { + std::string tn = detail::class_template_name< L >(); + std::string st = tn_add_each(); - return tn + '<' + st + '>' + suffix; -} + return tn + '<' + st + '>' + suffix; + } +}; #else -template class L, class T1> std::string type_name( tn_identity< L >, std::string const& suffix ) +template class L, class T1> struct tn_holder< L > { - std::string tn = class_template_name< L >(); - return tn + '<' + type_name( tn_identity(), "" ) + '>' + suffix; -} + static std::string type_name( std::string const& suffix ) + { + std::string tn = detail::class_template_name< L >(); + return tn + '<' + tn_holder::type_name( "" ) + '>' + suffix; + } +}; -template class L, class T1, class T2> std::string type_name( tn_identity< L >, std::string const& suffix ) +template class L, class T1, class T2> struct tn_holder< L > { - std::string tn = class_template_name< L >(); - return tn + '<' + type_name( tn_identity(), "" ) + ", " + type_name( tn_identity(), "" ) + '>' + suffix; -} + static std::string type_name( std::string const& suffix ) + { + std::string tn = detail::class_template_name< L >(); + return tn + '<' + tn_holder::type_name( "" ) + ", " + tn_holder::type_name( "" ) + '>' + suffix; + } +}; #endif // sequence containers -template class L, class T> std::string type_name( tn_identity< L > >, std::string const& suffix ) +template class L, class T> struct tn_holder< L > > { - std::string tn = sequence_template_name< L > >(); - return tn + '<' + type_name( tn_identity(), "" ) + '>' + suffix; -} + static std::string type_name( std::string const& suffix ) + { + std::string tn = detail::sequence_template_name< L > >(); + return tn + '<' + tn_holder::type_name( "" ) + '>' + suffix; + } +}; // set -template class L, class T> std::string type_name( tn_identity< L, std::allocator > >, std::string const& suffix ) +template class L, class T> struct tn_holder< L, std::allocator > > { - std::string tn = set_template_name< L, std::allocator > >(); - return tn + '<' + type_name( tn_identity(), "" ) + '>' + suffix; -} + static std::string type_name( std::string const& suffix ) + { + std::string tn = detail::set_template_name< L, std::allocator > >(); + return tn + '<' + tn_holder::type_name( "" ) + '>' + suffix; + } +}; // map -template class L, class T, class U> std::string type_name( tn_identity< L, std::allocator > > >, std::string const& suffix ) +template class L, class T, class U> struct tn_holder< L, std::allocator > > > { - std::string tn = map_template_name< L, std::allocator > > >(); - return tn + '<' + type_name( tn_identity(), "" ) + ", " + type_name( tn_identity(), "" ) + '>' + suffix; -} + static std::string type_name( std::string const& suffix ) + { + std::string tn = detail::map_template_name< L, std::allocator > > >(); + return tn + '<' + tn_holder::type_name( "" ) + ", " + tn_holder::type_name( "" ) + '>' + suffix; + } +}; #if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) // unordered_set -template class L, class T> std::string type_name( tn_identity< L, std::equal_to, std::allocator > >, std::string const& suffix ) +template class L, class T> struct tn_holder< L, std::equal_to, std::allocator > > { - std::string tn = set_template_name< L, std::equal_to, std::allocator > >(); - return tn + '<' + type_name( tn_identity(), "" ) + '>' + suffix; -} + static std::string type_name( std::string const& suffix ) + { + std::string tn = detail::set_template_name< L, std::equal_to, std::allocator > >(); + return tn + '<' + tn_holder::type_name( "" ) + '>' + suffix; + } +}; // unordered_map -template class L, class T, class U> std::string type_name( tn_identity< L, std::equal_to, std::allocator > > >, std::string const& suffix ) +template class L, class T, class U> struct tn_holder< L, std::equal_to, std::allocator > > > { - std::string tn = map_template_name< L, std::equal_to, std::allocator > > >(); - return tn + '<' + type_name( tn_identity(), "" ) + ", " + type_name( tn_identity(), "" ) + '>' + suffix; -} + static std::string type_name( std::string const& suffix ) + { + std::string tn = detail::map_template_name< L, std::equal_to, std::allocator > > >(); + return tn + '<' + tn_holder::type_name( "" ) + ", " + tn_holder::type_name( "" ) + '>' + suffix; + } +}; #endif // array -template class L, class T, std::size_t N> std::string type_name( tn_identity< L >, std::string const& suffix ) +template class L, class T, std::size_t N> struct tn_holder< L > { - std::string tn = array_template_name< L >(); - return tn + '<' + type_name( tn_identity(), "" ) + ", " + tn_to_string( N ) + '>' + suffix; -} + static std::string type_name( std::string const& suffix ) + { + std::string tn = detail::array_template_name< L >(); + return tn + '<' + tn_holder::type_name( "" ) + ", " + tn_to_string( N ) + '>' + suffix; + } +}; } // namespace detail template std::string type_name() { - return core::detail::type_name( core::detail::tn_identity(), "" ); + return core::detail::tn_holder::type_name( "" ); } } // namespace core diff --git a/test/type_name_test.cpp b/test/type_name_test.cpp index 6b61def..03c2fcd 100644 --- a/test/type_name_test.cpp +++ b/test/type_name_test.cpp @@ -27,6 +27,10 @@ # include #endif +#if !defined(BOOST_NO_CXX11_HDR_TUPLE) +# include +#endif + #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) # include #endif @@ -265,6 +269,9 @@ int main() TEST(std::pair); TEST(std::pair volatile&); + TEST(std::pair); + TEST(std::pair, void>); + TEST(std::basic_string); TEST(std::string); @@ -286,6 +293,8 @@ int main() TEST(X); TEST(X volatile&); + TEST(X, void>); + TEST(std::vector); TEST(std::vector); TEST(std::vector); @@ -326,6 +335,23 @@ int main() TEST(std::array); TEST(std::array const&); +#endif + +#if !defined(BOOST_NO_CXX11_HDR_TUPLE) + + TEST(std::tuple<>); + TEST(std::tuple); + TEST(std::tuple); + TEST(std::tuple); + + TEST(std::tuple); + TEST(std::tuple); + TEST(std::tuple); + + TEST(std::tuple, void>); + + TEST(X, void>); + #endif TEST(std::ostream);