diff --git a/include/boost/core/type_name.hpp b/include/boost/core/type_name.hpp index a2fd269..93927fe 100644 --- a/include/boost/core/type_name.hpp +++ b/include/boost/core/type_name.hpp @@ -21,6 +21,9 @@ #include #include #include +#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) +# include +#endif namespace boost { @@ -447,6 +450,12 @@ inline std::string type_name( tn_identity ) // strings +template class L, class Ch> std::string type_name( tn_identity< L, std::allocator > > ) +{ + std::string tn = sequence_template_name< L, std::allocator > >(); + return tn + '<' + type_name( tn_identity() ) + '>'; +} + inline std::string type_name( tn_identity ) { return "std::string"; @@ -484,6 +493,55 @@ inline std::string type_name( tn_identity> ) #endif +// string views (et al) + +template class L, class Ch> std::string type_name( tn_identity< L > > ) +{ + std::string tn = sequence_template_name< L > >(); + return tn + '<' + type_name( tn_identity() ) + '>'; +} + +#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) + +inline std::string type_name( tn_identity ) +{ + return "std::string_view"; +} + +inline std::string type_name( tn_identity ) +{ + return "std::wstring_view"; +} + +#if !defined(BOOST_NO_CXX11_CHAR16_T) + +inline std::string type_name( tn_identity ) +{ + return "std::u16string_view"; +} + +#endif + +#if !defined(BOOST_NO_CXX11_CHAR32_T) + +inline std::string type_name( tn_identity ) +{ + return "std::u32string_view"; +} + +#endif + +#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L + +inline std::string type_name( tn_identity> ) +{ + return "std::u8string_view"; +} + +#endif + +#endif + // class templates #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) diff --git a/test/type_name_test.cpp b/test/type_name_test.cpp index 84e73ed..61132cd 100644 --- a/test/type_name_test.cpp +++ b/test/type_name_test.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET) # include @@ -26,6 +27,10 @@ # include #endif +#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) +# include +#endif + // #define TEST(...) BOOST_TEST_EQ((boost::core::type_name<__VA_ARGS__>()), std::string(#__VA_ARGS__)) @@ -56,6 +61,10 @@ enum class E2 #endif +struct Ch +{ +}; + int main() { TEST(int); @@ -121,6 +130,8 @@ int main() TEST(std::pair); TEST(std::pair volatile&); + TEST(std::basic_string); + TEST(std::string); TEST(std::wstring); @@ -181,5 +192,31 @@ int main() TEST(std::array const&); #endif + + TEST(std::basic_ostream); + TEST(std::basic_ostream); + +#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) + + TEST(std::basic_string_view); + + TEST(std::string_view); + TEST(std::wstring_view); + +#if BOOST_CXX_VERSION >= 201100L + + TEST(std::u16string_view); + TEST(std::u32string_view); + +#endif + +#if BOOST_CXX_VERSION >= 202000L + + TEST(std::u8string_view); + +#endif + +#endif + return boost::report_errors(); }