From d2361fe05a97660bd764ceef7fade94eadabd9e3 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Wed, 4 Jul 2012 18:50:56 +0000 Subject: [PATCH] Updated documentaion, fixed bug and refactored tests (refs #7065) [SVN r79266] --- doc/lexical_cast.qbk | 1 + include/boost/lexical_cast.hpp | 12 +++ test/lexical_cast_arrays_test.cpp | 139 ++++++++++++++++++++++++++---- 3 files changed, 136 insertions(+), 16 deletions(-) diff --git a/doc/lexical_cast.qbk b/doc/lexical_cast.qbk index 1100666..dcc61af 100644 --- a/doc/lexical_cast.qbk +++ b/doc/lexical_cast.qbk @@ -112,6 +112,7 @@ The character type of the underlying stream is assumed to be `char` unless eithe * Arrays of characters: `wchar_t *`, `char16_t *`, `char32_t *`, `const wchar_t *`, `const char16_t *`, `const char32_t *` * Strings: `std::basic_string`, `boost::containers::basic_string` * `boost::iterator_range`, where `WideCharPtr` is a pointer to wide-character or pointer to const wide-character +* `boost::array` and `std::array`, `boost::array` and `std::array` [important Many compilers and runtime libraries fail to make conversions using new Unicode characters. Make shure that the following code compiles and outputs nonzero values, before using new types: `` diff --git a/include/boost/lexical_cast.hpp b/include/boost/lexical_cast.hpp index 33ef84b..c9d4a59 100644 --- a/include/boost/lexical_cast.hpp +++ b/include/boost/lexical_cast.hpp @@ -272,12 +272,24 @@ namespace boost { typedef BOOST_DEDUCED_TYPENAME stream_char::type type; }; + template + struct stream_char > + { + typedef BOOST_DEDUCED_TYPENAME stream_char::type type; + }; + #if !defined(BOOST_NO_CXX11_HDR_ARRAY) && defined(BOOST_HAS_TR1_ARRAY) template struct stream_char > { typedef BOOST_DEDUCED_TYPENAME stream_char::type type; }; + + template + struct stream_char > + { + typedef BOOST_DEDUCED_TYPENAME stream_char::type type; + }; #endif // !defined(BOOST_NO_CXX11_HDR_ARRAY) && defined(BOOST_HAS_TR1_ARRAY) #if !defined(BOOST_LCAST_NO_WCHAR_T) && defined(BOOST_NO_INTRINSIC_WCHAR_T) diff --git a/test/lexical_cast_arrays_test.cpp b/test/lexical_cast_arrays_test.cpp index c9213f4..6aff2d9 100644 --- a/test/lexical_cast_arrays_test.cpp +++ b/test/lexical_cast_arrays_test.cpp @@ -11,7 +11,7 @@ #include #include - + #include void testing_boost_array_output_conversion(); @@ -80,15 +80,11 @@ static void testing_template_array_output_on_spec_value(T val) { warr_type res = lexical_cast(val); BOOST_CHECK(res.begin() == wethalon); - warr_type res3 = lexical_cast(wethalon); - BOOST_CHECK(res.begin() == wethalon); } { const warr_type res = lexical_cast(val); BOOST_CHECK(res.begin() == wethalon); - const warr_type res3 = lexical_cast(wethalon); - BOOST_CHECK(res.begin() == wethalon); } BOOST_CHECK_THROW(lexical_cast(val), boost::bad_lexical_cast); @@ -103,17 +99,11 @@ static void testing_template_array_output_on_spec_value(T val) { u16arr_type res = lexical_cast(val); BOOST_CHECK(res.begin() == u16ethalon); - - u16arr_type res3 = lexical_cast(u16ethalon); - BOOST_CHECK(res3.begin() == u16ethalon); } { const u16arr_type res = lexical_cast(val); BOOST_CHECK(res.begin() == u16ethalon); - - const u16arr_type res3 = lexical_cast(u16ethalon); - BOOST_CHECK(res3.begin() == u16ethalon); } BOOST_CHECK_THROW(lexical_cast(val), boost::bad_lexical_cast); @@ -127,15 +117,125 @@ static void testing_template_array_output_on_spec_value(T val) { u32arr_type res = lexical_cast(val); BOOST_CHECK(res.begin() == u32ethalon); - - u32arr_type res3 = lexical_cast(u32ethalon); - BOOST_CHECK(res3.begin() == u32ethalon); } { const u32arr_type res = lexical_cast(val); BOOST_CHECK(res.begin() == u32ethalon); + } + + BOOST_CHECK_THROW(lexical_cast(val), boost::bad_lexical_cast); +#endif +} + +template