Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85852 - in trunk: boost libs/conversion/example
From: antoshkka_at_[hidden]
Date: 2013-09-23 07:59:06


Author: apolukhin
Date: 2013-09-23 07:59:06 EDT (Mon, 23 Sep 2013)
New Revision: 85852
URL: http://svn.boost.org/trac/boost/changeset/85852

Log:
lexical_cast.hpp improvements: fix bug with floats conversions and improve docs (refs #9046)

Text files modified:
   trunk/boost/lexical_cast.hpp | 48 +++++++++++++++++++--------------------
   trunk/libs/conversion/example/generic_stringize.cpp | 11 +++++---
   2 files changed, 30 insertions(+), 29 deletions(-)

Modified: trunk/boost/lexical_cast.hpp
==============================================================================
--- trunk/boost/lexical_cast.hpp Mon Sep 23 06:03:44 2013 (r85851)
+++ trunk/boost/lexical_cast.hpp 2013-09-23 07:59:06 EDT (Mon, 23 Sep 2013) (r85852)
@@ -1446,74 +1446,74 @@
             }
 
             template <class T, class SomeCharT>
- bool shl_real_type(const T& val, SomeCharT* /*begin*/, SomeCharT*& /*end*/) {
+ bool shl_real_type(const T& val, SomeCharT* /*begin*/) {
                 lcast_set_precision(out_stream, &val);
                 return shl_input_streamable(val);
             }
 
- static bool shl_real_type(float val, char* begin, char*& end) {
+ bool shl_real_type(float val, char* begin) {
                 using namespace std;
                 const double val_as_double = val;
- end = begin +
+ finish = start +
 #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
- sprintf_s(begin, end-begin,
+ sprintf_s(begin, CharacterBufferSize,
 #else
                     sprintf(begin,
 #endif
                     "%.*g", static_cast<int>(boost::detail::lcast_get_precision<float>()), val_as_double);
- return end > begin;
+ return finish > start;
             }
 
- static bool shl_real_type(double val, char* begin, char*& end) {
+ bool shl_real_type(double val, char* begin) {
                 using namespace std;
- end = begin +
+ finish = start +
 #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
- sprintf_s(begin, end-begin,
+ sprintf_s(begin, CharacterBufferSize,
 #else
                     sprintf(begin,
 #endif
                     "%.*g", static_cast<int>(boost::detail::lcast_get_precision<double>()), val);
- return end > begin;
+ return finish > start;
             }
 
 #ifndef __MINGW32__
- static bool shl_real_type(long double val, char* begin, char*& end) {
+ bool shl_real_type(long double val, char* begin) {
                 using namespace std;
- end = begin +
+ finish = start +
 #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
- sprintf_s(begin, end-begin,
+ sprintf_s(begin, CharacterBufferSize,
 #else
                     sprintf(begin,
 #endif
                     "%.*Lg", static_cast<int>(boost::detail::lcast_get_precision<long double>()), val );
- return end > begin;
+ return finish > start;
             }
 #endif
 
 
 #if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_SWPRINTF) && !defined(__MINGW32__)
- static bool shl_real_type(float val, wchar_t* begin, wchar_t*& end) {
+ bool shl_real_type(float val, wchar_t* begin) {
                 using namespace std;
                 const double val_as_double = val;
- end = begin + swprintf(begin, end-begin,
+ finish = start + swprintf(begin, CharacterBufferSize,
                                        L"%.*g",
                                        static_cast<int>(boost::detail::lcast_get_precision<float >()),
                                        val_as_double );
- return end > begin;
+ return finish > start;
             }
 
- static bool shl_real_type(double val, wchar_t* begin, wchar_t*& end) {
+ bool shl_real_type(double val, wchar_t* begin) {
                 using namespace std;
- end = begin + swprintf(begin, end-begin,
+ finish = start + swprintf(begin, CharacterBufferSize,
                                           L"%.*g", static_cast<int>(boost::detail::lcast_get_precision<double >()), val );
- return end > begin;
+ return finish > start;
             }
 
- static bool shl_real_type(long double val, wchar_t* begin, wchar_t*& end) {
+ bool shl_real_type(long double val, wchar_t* begin) {
                 using namespace std;
- end = begin + swprintf(begin, end-begin,
+ finish = start + swprintf(begin, CharacterBufferSize,
                                           L"%.*Lg", static_cast<int>(boost::detail::lcast_get_precision<long double >()), val );
- return end > begin;
+ return finish > start;
             }
 #endif
             template <class T>
@@ -1524,9 +1524,7 @@
                     return true;
                 }
 
- bool const result = shl_real_type(val, static_cast<CharT*>(buffer), tmp_finish);
- finish = tmp_finish;
- return result;
+ return shl_real_type(val, static_cast<CharT*>(buffer));
             }
 
 /************************************ OPERATORS << ( ... ) ********************************/

Modified: trunk/libs/conversion/example/generic_stringize.cpp
==============================================================================
--- trunk/libs/conversion/example/generic_stringize.cpp Mon Sep 23 06:03:44 2013 (r85851)
+++ trunk/libs/conversion/example/generic_stringize.cpp 2013-09-23 07:59:06 EDT (Mon, 23 Sep 2013) (r85852)
@@ -44,16 +44,19 @@
 }
 
 //` Step 3: Using the `stringize` with different types:
-#include <iostream>
+#include <cassert>
 #include <boost/fusion/adapted/boost_tuple.hpp>
 #include <boost/fusion/adapted/std_pair.hpp>
 
 int main() {
     boost::tuple<char, int, char, int> decim('-', 10, 'e', 5);
- std::pair<short, std::string> value_and_type(270, "Kelvin");
+ assert(stringize(decim) == "-10e5");
 
- std::cout << stringize(decim) << '\n' // outputs '-10e5'
- << stringize(value_and_type); // outputs '270Kelvin'
+ std::pair<short, std::string> value_and_type(270, "Kelvin");
+ assert(stringize(value_and_type) == "270Kelvin");
 }
 
 //] [/lexical_cast_stringize]
+
+
+


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