diff --git a/include/boost/core/type_name.hpp b/include/boost/core/type_name.hpp index 66ec916..edd3dd2 100644 --- a/include/boost/core/type_name.hpp +++ b/include/boost/core/type_name.hpp @@ -131,6 +131,11 @@ template std::string map_template_name() return class_template_name(); } +template std::string array_template_name() +{ + return class_template_name(); +} + #else // #if !defined(BOOST_NO_TYPEID) template std::string typeid_name() @@ -158,6 +163,11 @@ template std::string map_template_name() return "_Mp"; } +template std::string array_template_name() +{ + return "_Ar"; +} + #endif // tn_to_string @@ -167,10 +177,10 @@ template std::string map_template_name() # pragma warning( disable: 4996 ) #endif -inline std::string tn_to_string( unsigned long n ) +inline std::string tn_to_string( std::size_t n ) { char buffer[ 32 ]; - std::sprintf( buffer, "%lu", n ); + std::sprintf( buffer, "%lu", static_cast< unsigned long >( n ) ); return buffer; } @@ -351,7 +361,7 @@ template std::pair array_prefi { std::pair r = array_prefix_suffix( tn_identity() ); - r.second = '[' + tn_to_string( static_cast( N ) ) + ']' + r.second; + r.second = '[' + tn_to_string( N ) + ']' + r.second; return r; } @@ -530,6 +540,14 @@ template class L, class T #endif +// array + +template class L, class T, std::size_t N> std::string type_name( tn_identity< L > ) +{ + std::string tn = array_template_name< L >(); + return tn + '<' + type_name( tn_identity() ) + ", " + tn_to_string( N ) + '>'; +} + } // namespace detail template std::string type_name() diff --git a/test/type_name_test.cpp b/test/type_name_test.cpp index 6381a22..cd42f62 100644 --- a/test/type_name_test.cpp +++ b/test/type_name_test.cpp @@ -22,6 +22,10 @@ # include #endif +#if !defined(BOOST_NO_CXX11_HDR_ARRAY) +# include +#endif + // #define TEST(...) BOOST_TEST_EQ((boost::core::type_name<__VA_ARGS__>()), std::string(#__VA_ARGS__)) @@ -149,5 +153,11 @@ int main() #endif +#if !defined(BOOST_NO_CXX11_HDR_ARRAY) + + TEST(std::array); + TEST(std::array const&); + +#endif return boost::report_errors(); }