Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83542 - in branches/release: boost libs/conversion libs/conversion/test
From: antoshkka_at_[hidden]
Date: 2013-03-24 10:37:57


Author: apolukhin
Date: 2013-03-24 10:37:56 EDT (Sun, 24 Mar 2013)
New Revision: 83542
URL: http://svn.boost.org/trac/boost/changeset/83542

Log:
Merge from trunk:
* Fixed incorrect usage of Boost.Math when it does not support long double (fixes #8162)
* Fixed ambiguity of boost::lexical_cast functions (fixes #7421)
Text files modified:
   branches/release/boost/lexical_cast.hpp | 65 ++++++++++++++++++++++++++++++++++-----
   branches/release/libs/conversion/lexical_cast_test.cpp | 5 +++
   branches/release/libs/conversion/test/lexical_cast_empty_input_test.cpp | 2 +
   branches/release/libs/conversion/test/lexical_cast_iterator_range_test.cpp | 6 +++
   branches/release/libs/conversion/test/lexical_cast_no_locale_test.cpp | 2 +
   5 files changed, 71 insertions(+), 9 deletions(-)

Modified: branches/release/boost/lexical_cast.hpp
==============================================================================
--- branches/release/boost/lexical_cast.hpp (original)
+++ branches/release/boost/lexical_cast.hpp 2013-03-24 10:37:56 EDT (Sun, 24 Mar 2013)
@@ -1172,16 +1172,20 @@
         struct mantissa_holder_type<float>
         {
             typedef unsigned int type;
+ typedef double wide_result_t;
         };
 
         template <>
         struct mantissa_holder_type<double>
         {
+#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
         };
 
         template<class Traits, class T, class CharT>
@@ -1218,6 +1222,7 @@
 
             typedef typename Traits::int_type int_type;
             typedef BOOST_DEDUCED_TYPENAME mantissa_holder_type<T>::type mantissa_type;
+ typedef BOOST_DEDUCED_TYPENAME mantissa_holder_type<T>::wide_result_t wide_result_t;
             int_type const zero = Traits::to_int_type(czero);
             if (begin == end) return false;
 
@@ -1396,7 +1401,7 @@
             /* 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<wide_result_t>(10.0), pow_of_10) * mantissa;
             value = static_cast<T>( has_minus ? (boost::math::changesign)(result) : result);
 
             if ( (boost::math::isinf)(value) || (boost::math::isnan)(value) ) return false;
@@ -2121,10 +2126,10 @@
                  * 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,16 +2446,58 @@
         return caster_type::lexical_cast_impl(arg);
     }
 
- template <typename Target, typename CharType>
- inline Target lexical_cast(const CharType* chars, std::size_t count)
+ template <typename Target>
+ inline Target lexical_cast(const char* chars, std::size_t count)
+ {
+ return ::boost::lexical_cast<Target>(
+ ::boost::iterator_range<const char*>(chars, chars + count)
+ );
+ }
+
+
+ template <typename Target>
+ inline Target lexical_cast(const unsigned char* chars, std::size_t count)
     {
- BOOST_STATIC_ASSERT_MSG(boost::detail::is_char_or_wchar<CharType>::value,
- "CharType must be a character or wide character type");
+ return ::boost::lexical_cast<Target>(
+ ::boost::iterator_range<const unsigned char*>(chars, chars + count)
+ );
+ }
 
- return boost::lexical_cast<Target>(
- boost::iterator_range<const CharType*>(chars, chars + count)
+ template <typename Target>
+ inline Target lexical_cast(const signed char* chars, std::size_t count)
+ {
+ return ::boost::lexical_cast<Target>(
+ ::boost::iterator_range<const signed char*>(chars, chars + count)
+ );
+ }
+
+#ifndef BOOST_LCAST_NO_WCHAR_T
+ template <typename Target>
+ inline Target lexical_cast(const wchar_t* chars, std::size_t count)
+ {
+ return ::boost::lexical_cast<Target>(
+ ::boost::iterator_range<const wchar_t*>(chars, chars + count)
+ );
+ }
+#endif
+#ifndef BOOST_NO_CHAR16_T
+ template <typename Target>
+ inline Target lexical_cast(const char16_t* chars, std::size_t count)
+ {
+ return ::boost::lexical_cast<Target>(
+ ::boost::iterator_range<const char16_t*>(chars, chars + count)
         );
     }
+#endif
+#ifndef BOOST_NO_CHAR32_T
+ template <typename Target>
+ inline Target lexical_cast(const char32_t* chars, std::size_t count)
+ {
+ return ::boost::lexical_cast<Target>(
+ ::boost::iterator_range<const char32_t*>(chars, chars + count)
+ );
+ }
+#endif
 
 } // namespace boost
 

Modified: branches/release/libs/conversion/lexical_cast_test.cpp
==============================================================================
--- branches/release/libs/conversion/lexical_cast_test.cpp (original)
+++ branches/release/libs/conversion/lexical_cast_test.cpp 2013-03-24 10:37:56 EDT (Sun, 24 Mar 2013)
@@ -36,6 +36,7 @@
 #include <boost/type_traits/integral_promotion.hpp>
 #include <string>
 #include <vector>
+#include <algorithm> // std::transform
 #include <memory>
 
 #if (defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)) \
@@ -622,6 +623,10 @@
     typedef std::string(*f3)(const int&);
     f3 p3 = &boost::lexical_cast<std::string, int>;
     BOOST_CHECK(p3);
+
+ std::vector<int> values;
+ std::vector<std::string> ret;
+ std::transform(values.begin(), values.end(), ret.begin(), boost::lexical_cast<std::string, int>);
 }
 
 

Modified: branches/release/libs/conversion/test/lexical_cast_empty_input_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_empty_input_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_empty_input_test.cpp 2013-03-24 10:37:56 EDT (Sun, 24 Mar 2013)
@@ -32,7 +32,9 @@
     BOOST_CHECK_THROW(lexical_cast<int>(v), bad_lexical_cast);
     BOOST_CHECK_THROW(lexical_cast<float>(v), bad_lexical_cast);
     BOOST_CHECK_THROW(lexical_cast<double>(v), bad_lexical_cast);
+#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
     BOOST_CHECK_THROW(lexical_cast<long double>(v), bad_lexical_cast);
+#endif
     BOOST_CHECK_THROW(lexical_cast<unsigned int>(v), bad_lexical_cast);
     BOOST_CHECK_THROW(lexical_cast<unsigned short>(v), bad_lexical_cast);
 #if defined(BOOST_HAS_LONG_LONG)

Modified: branches/release/libs/conversion/test/lexical_cast_iterator_range_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_iterator_range_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_iterator_range_test.cpp 2013-03-24 10:37:56 EDT (Sun, 24 Mar 2013)
@@ -63,8 +63,10 @@
     BOOST_CHECK_EQUAL(lexical_cast<float>(rng.begin(), rng.size()), 1.0f);
     BOOST_CHECK_EQUAL(lexical_cast<double>(rng), 1.0);
     BOOST_CHECK_EQUAL(lexical_cast<double>(rng.begin(), rng.size()), 1.0);
+#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
     BOOST_CHECK_EQUAL(lexical_cast<long double>(rng), 1.0L);
     BOOST_CHECK_EQUAL(lexical_cast<long double>(rng.begin(), rng.size()), 1.0L);
+#endif
     BOOST_CHECK_EQUAL(lexical_cast<class_with_user_defined_sream_operators>(rng), 1);
 #endif
 #if defined(BOOST_HAS_LONG_LONG)
@@ -119,12 +121,16 @@
 
     BOOST_CHECK_EQUAL(lexical_cast<float>(rng1), 1.0f);
     BOOST_CHECK_EQUAL(lexical_cast<double>(rng1), 1.0);
+#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
     BOOST_CHECK_EQUAL(lexical_cast<long double>(rng1), 1.0L);
+#endif
     BOOST_CHECK_EQUAL(lexical_cast<class_with_user_defined_sream_operators>(rng1), 1);
 
     BOOST_CHECK_EQUAL(lexical_cast<float>(crng2), 1.0f);
     BOOST_CHECK_EQUAL(lexical_cast<double>(crng2), 1.0);
+#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
     BOOST_CHECK_EQUAL(lexical_cast<long double>(crng2), 1.0L);
+#endif
     BOOST_CHECK_EQUAL(lexical_cast<class_with_user_defined_sream_operators>(crng2), 1);
 
 #ifndef BOOST_LCAST_NO_WCHAR_T

Modified: branches/release/libs/conversion/test/lexical_cast_no_locale_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_no_locale_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_no_locale_test.cpp 2013-03-24 10:37:56 EDT (Sun, 24 Mar 2013)
@@ -37,7 +37,9 @@
     BOOST_CHECK_THROW(lexical_cast<int>(v), bad_lexical_cast);
     BOOST_CHECK_THROW(lexical_cast<float>(v), bad_lexical_cast);
     BOOST_CHECK_THROW(lexical_cast<double>(v), bad_lexical_cast);
+#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
     BOOST_CHECK_THROW(lexical_cast<long double>(v), bad_lexical_cast);
+#endif
     BOOST_CHECK_THROW(lexical_cast<unsigned int>(v), bad_lexical_cast);
     BOOST_CHECK_THROW(lexical_cast<unsigned short>(v), bad_lexical_cast);
 #if defined(BOOST_HAS_LONG_LONG)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk