diff --git a/include/boost/lexical_cast.hpp b/include/boost/lexical_cast.hpp index 2b1d95a..cca8844 100644 --- a/include/boost/lexical_cast.hpp +++ b/include/boost/lexical_cast.hpp @@ -1172,15 +1172,19 @@ namespace boost { struct mantissa_holder_type { typedef unsigned int type; + typedef double wide_result_t; }; template <> struct mantissa_holder_type { +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS + typedef long double wide_result_t; #if defined(BOOST_HAS_LONG_LONG) typedef boost::ulong_long_type type; #elif defined(BOOST_HAS_MS_INT64) typedef unsigned __int64 type; +#endif #endif }; @@ -1218,6 +1222,7 @@ namespace boost { typedef typename Traits::int_type int_type; typedef BOOST_DEDUCED_TYPENAME mantissa_holder_type::type mantissa_type; + typedef BOOST_DEDUCED_TYPENAME mantissa_holder_type::wide_result_t wide_result_t; int_type const zero = Traits::to_int_type(czero); if (begin == end) return false; @@ -1396,7 +1401,7 @@ namespace boost { /* We need a more accurate algorithm... We can not use current algorithm * with long doubles (and with doubles if sizeof(double)==sizeof(long double)). */ - long double result = std::pow(10.0L, pow_of_10) * mantissa; + const wide_result_t result = std::pow(static_cast(10.0), pow_of_10) * mantissa; value = static_cast( has_minus ? (boost::math::changesign)(result) : result); if ( (boost::math::isinf)(value) || (boost::math::isnan)(value) ) return false; @@ -2121,10 +2126,10 @@ namespace boost { * double, because it will give a big precision loss. * */ boost::mpl::if_c< -#if defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64) +#if (defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) boost::type_traits::ice_eq< sizeof(double), sizeof(long double) >::value, #else - 0 + 1, #endif int, char @@ -2441,17 +2446,59 @@ namespace boost { return caster_type::lexical_cast_impl(arg); } - template - inline Target lexical_cast(const CharType* chars, std::size_t count) - { - BOOST_STATIC_ASSERT_MSG(boost::detail::is_char_or_wchar::value, - "CharType must be a character or wide character type"); - - return boost::lexical_cast( - boost::iterator_range(chars, chars + count) + template + inline Target lexical_cast(const char* chars, std::size_t count) + { + return ::boost::lexical_cast( + ::boost::iterator_range(chars, chars + count) ); } + + template + inline Target lexical_cast(const unsigned char* chars, std::size_t count) + { + return ::boost::lexical_cast( + ::boost::iterator_range(chars, chars + count) + ); + } + + template + inline Target lexical_cast(const signed char* chars, std::size_t count) + { + return ::boost::lexical_cast( + ::boost::iterator_range(chars, chars + count) + ); + } + +#ifndef BOOST_LCAST_NO_WCHAR_T + template + inline Target lexical_cast(const wchar_t* chars, std::size_t count) + { + return ::boost::lexical_cast( + ::boost::iterator_range(chars, chars + count) + ); + } +#endif +#ifndef BOOST_NO_CHAR16_T + template + inline Target lexical_cast(const char16_t* chars, std::size_t count) + { + return ::boost::lexical_cast( + ::boost::iterator_range(chars, chars + count) + ); + } +#endif +#ifndef BOOST_NO_CHAR32_T + template + inline Target lexical_cast(const char32_t* chars, std::size_t count) + { + return ::boost::lexical_cast( + ::boost::iterator_range(chars, chars + count) + ); + } +#endif + } // namespace boost #else // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION diff --git a/lexical_cast_test.cpp b/lexical_cast_test.cpp index 18e063b..b7b7fb3 100644 --- a/lexical_cast_test.cpp +++ b/lexical_cast_test.cpp @@ -36,6 +36,7 @@ #include #include #include +#include // std::transform #include #if (defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)) \ @@ -622,6 +623,10 @@ void test_getting_pointer_to_function() typedef std::string(*f3)(const int&); f3 p3 = &boost::lexical_cast; BOOST_CHECK(p3); + + std::vector values; + std::vector ret; + std::transform(values.begin(), values.end(), ret.begin(), boost::lexical_cast); } diff --git a/test/lexical_cast_empty_input_test.cpp b/test/lexical_cast_empty_input_test.cpp index e307ea2..d16fd02 100755 --- a/test/lexical_cast_empty_input_test.cpp +++ b/test/lexical_cast_empty_input_test.cpp @@ -32,7 +32,9 @@ void do_test_on_empty_input(T& v) BOOST_CHECK_THROW(lexical_cast(v), bad_lexical_cast); BOOST_CHECK_THROW(lexical_cast(v), bad_lexical_cast); BOOST_CHECK_THROW(lexical_cast(v), bad_lexical_cast); +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS BOOST_CHECK_THROW(lexical_cast(v), bad_lexical_cast); +#endif BOOST_CHECK_THROW(lexical_cast(v), bad_lexical_cast); BOOST_CHECK_THROW(lexical_cast(v), bad_lexical_cast); #if defined(BOOST_HAS_LONG_LONG) diff --git a/test/lexical_cast_iterator_range_test.cpp b/test/lexical_cast_iterator_range_test.cpp index a50528b..20d850c 100644 --- a/test/lexical_cast_iterator_range_test.cpp +++ b/test/lexical_cast_iterator_range_test.cpp @@ -63,8 +63,10 @@ void do_test_iterator_range_impl(const RngT& rng) BOOST_CHECK_EQUAL(lexical_cast(rng.begin(), rng.size()), 1.0f); BOOST_CHECK_EQUAL(lexical_cast(rng), 1.0); BOOST_CHECK_EQUAL(lexical_cast(rng.begin(), rng.size()), 1.0); +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS BOOST_CHECK_EQUAL(lexical_cast(rng), 1.0L); BOOST_CHECK_EQUAL(lexical_cast(rng.begin(), rng.size()), 1.0L); +#endif BOOST_CHECK_EQUAL(lexical_cast(rng), 1); #endif #if defined(BOOST_HAS_LONG_LONG) @@ -119,12 +121,16 @@ void test_it_range_using_char(CharT* one, CharT* eleven) BOOST_CHECK_EQUAL(lexical_cast(rng1), 1.0f); BOOST_CHECK_EQUAL(lexical_cast(rng1), 1.0); +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS BOOST_CHECK_EQUAL(lexical_cast(rng1), 1.0L); +#endif BOOST_CHECK_EQUAL(lexical_cast(rng1), 1); BOOST_CHECK_EQUAL(lexical_cast(crng2), 1.0f); BOOST_CHECK_EQUAL(lexical_cast(crng2), 1.0); +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS BOOST_CHECK_EQUAL(lexical_cast(crng2), 1.0L); +#endif BOOST_CHECK_EQUAL(lexical_cast(crng2), 1); #ifndef BOOST_LCAST_NO_WCHAR_T diff --git a/test/lexical_cast_no_locale_test.cpp b/test/lexical_cast_no_locale_test.cpp index 2a5120b..01702db 100755 --- a/test/lexical_cast_no_locale_test.cpp +++ b/test/lexical_cast_no_locale_test.cpp @@ -37,7 +37,9 @@ void do_test_on_empty_input(T& v) BOOST_CHECK_THROW(lexical_cast(v), bad_lexical_cast); BOOST_CHECK_THROW(lexical_cast(v), bad_lexical_cast); BOOST_CHECK_THROW(lexical_cast(v), bad_lexical_cast); +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS BOOST_CHECK_THROW(lexical_cast(v), bad_lexical_cast); +#endif BOOST_CHECK_THROW(lexical_cast(v), bad_lexical_cast); BOOST_CHECK_THROW(lexical_cast(v), bad_lexical_cast); #if defined(BOOST_HAS_LONG_LONG)