Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77288 - in branches/release: boost boost/numeric/conversion libs/conversion/doc libs/conversion/perf libs/conversion/test
From: antoshkka_at_[hidden]
Date: 2012-03-10 02:31:38


Author: apolukhin
Date: 2012-03-10 02:31:36 EST (Sat, 10 Mar 2012)
New Revision: 77288
URL: http://svn.boost.org/trac/boost/changeset/77288

Log:
Merge from trunk
* Much more tests
* Now numeric_cast (and lexical_cast) can be compiled with disabled exceptions
* Supress warning described in #6645 (implicit conversion shortens 64-bit value into a 32-bit value)
* Fixed compilation of lexical_cast with BOOST_NO_STD_LOCALE defined
* Documentation updates
* Case insensitive "NaN" and "Inf" parsing
* Performance tests commit
Added:
   branches/release/libs/conversion/perf/
   branches/release/libs/conversion/perf/Jamfile.v2 (contents, props changed)
   branches/release/libs/conversion/perf/performance_test.cpp (contents, props changed)
   branches/release/libs/conversion/test/lexical_cast_no_exceptions_test.cpp (contents, props changed)
   branches/release/libs/conversion/test/lexical_cast_no_locale_test.cpp (contents, props changed)
Text files modified:
   branches/release/boost/lexical_cast.hpp | 277 +++++++++++++++++++++------------------
   branches/release/boost/numeric/conversion/converter_policies.hpp | 8 +
   branches/release/libs/conversion/doc/lexical_cast.qbk | 15 ++
   branches/release/libs/conversion/test/Jamfile.v2 | 11 +
   branches/release/libs/conversion/test/lexical_cast_containers_test.cpp | 22 +++
   branches/release/libs/conversion/test/lexical_cast_empty_input_test.cpp | 14 ++
   branches/release/libs/conversion/test/lexical_cast_inf_nan_test.cpp | 21 +++
   branches/release/libs/conversion/test/lexical_cast_typedefed_wchar_test.cpp | 15 ++
   8 files changed, 249 insertions(+), 134 deletions(-)

Modified: branches/release/boost/lexical_cast.hpp
==============================================================================
--- branches/release/boost/lexical_cast.hpp (original)
+++ branches/release/boost/lexical_cast.hpp 2012-03-10 02:31:36 EST (Sat, 10 Mar 2012)
@@ -104,7 +104,7 @@
 namespace boost
 {
     // exception used to indicate runtime lexical_cast failure
- class bad_lexical_cast :
+ class BOOST_SYMBOL_VISIBLE bad_lexical_cast :
     // workaround MSVC bug with std::bad_cast when _HAS_EXCEPTIONS == 0
 #if defined(BOOST_MSVC) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS
         public std::exception
@@ -732,6 +732,15 @@
 
     namespace detail
     {
+ template <class CharT>
+ bool lc_iequal(const CharT* val, const CharT* lcase, const CharT* ucase, unsigned int len) {
+ for( unsigned int i=0; i < len; ++i ) {
+ if ( val[i] != lcase[i] && val[i] != ucase[i] ) return false;
+ }
+
+ return true;
+ }
+
         /* Returns true and sets the correct value if found NaN or Inf. */
         template <class CharT, class T>
         inline bool parse_inf_nan_impl(const CharT* begin, const CharT* end, T& value
@@ -755,7 +764,7 @@
             else if( *begin == plus ) ++begin;
 
             if( end-begin < 3 ) return false;
- if( !memcmp(begin, lc_nan, 3*sizeof(CharT)) || !memcmp(begin, lc_NAN, 3*sizeof(CharT)) )
+ if( lc_iequal(begin, lc_nan, lc_NAN, 3) )
             {
                 begin += 3;
                 if (end != begin) /* It is 'nan(...)' or some bad input*/
@@ -772,13 +781,13 @@
             if (( /* 'INF' or 'inf' */
                   end-begin==3
                   &&
- (!memcmp(begin, lc_infinity, 3*sizeof(CharT)) || !memcmp(begin, lc_INFINITY, 3*sizeof(CharT)))
+ lc_iequal(begin, lc_infinity, lc_INFINITY, 3)
                 )
                 ||
                 ( /* 'INFINITY' or 'infinity' */
                   end-begin==inifinity_size
                   &&
- (!memcmp(begin, lc_infinity, inifinity_size)|| !memcmp(begin, lc_INFINITY, inifinity_size))
+ lc_iequal(begin, lc_infinity, lc_INFINITY, inifinity_size)
                 )
              )
             {
@@ -790,6 +799,41 @@
             return false;
         }
 
+ template <class CharT, class T>
+ bool put_inf_nan_impl(CharT* begin, CharT*& end, const T& value
+ , const CharT* lc_nan
+ , const CharT* lc_infinity)
+ {
+ using namespace std;
+ const CharT minus = lcast_char_constants<CharT>::minus;
+ if ( (boost::math::isnan)(value) )
+ {
+ if ( (boost::math::signbit)(value) )
+ {
+ *begin = minus;
+ ++ begin;
+ }
+
+ memcpy(begin, lc_nan, 3 * sizeof(CharT));
+ end = begin + 3;
+ return true;
+ } else if ( (boost::math::isinf)(value) )
+ {
+ if ( (boost::math::signbit)(value) )
+ {
+ *begin = minus;
+ ++ begin;
+ }
+
+ memcpy(begin, lc_infinity, 3 * sizeof(CharT));
+ end = begin + 3;
+ return true;
+ }
+
+ return false;
+ }
+
+
 #ifndef BOOST_LCAST_NO_WCHAR_T
         template <class T>
         bool parse_inf_nan(const wchar_t* begin, const wchar_t* end, T& value)
@@ -799,6 +843,13 @@
                                , L"INFINITY", L"infinity"
                                , L'(', L')');
         }
+
+ template <class T>
+ bool put_inf_nan(wchar_t* begin, wchar_t*& end, const T& value)
+ {
+ return put_inf_nan_impl(begin, end, value, L"nan", L"infinity");
+ }
+
 #endif
 #ifndef BOOST_NO_CHAR16_T
         template <class T>
@@ -809,6 +860,12 @@
                                , u"INFINITY", u"infinity"
                                , u'(', u')');
         }
+
+ template <class T>
+ bool put_inf_nan(char16_t* begin, char16_t*& end, const T& value)
+ {
+ return put_inf_nan_impl(begin, end, value, u"nan", u"infinity");
+ }
 #endif
 #ifndef BOOST_NO_CHAR32_T
         template <class T>
@@ -819,6 +876,12 @@
                                , U"INFINITY", U"infinity"
                                , U'(', U')');
         }
+
+ template <class T>
+ bool put_inf_nan(char32_t* begin, char32_t*& end, const T& value)
+ {
+ return put_inf_nan_impl(begin, end, value, U"nan", U"infinity");
+ }
 #endif
 
         template <class CharT, class T>
@@ -829,73 +892,12 @@
                                , "INFINITY", "infinity"
                                , '(', ')');
         }
-#ifndef BOOST_LCAST_NO_WCHAR_T
- template <class T>
- bool put_inf_nan(wchar_t* begin, wchar_t*& end, const T& value)
- {
- using namespace std;
- if ( (boost::math::isnan)(value) )
- {
- if ( (boost::math::signbit)(value) )
- {
- memcpy(begin,L"-nan", sizeof(L"-nan"));
- end = begin + 4;
- } else
- {
- memcpy(begin,L"nan", sizeof(L"nan"));
- end = begin + 3;
- }
- return true;
- } else if ( (boost::math::isinf)(value) )
- {
- if ( (boost::math::signbit)(value) )
- {
- memcpy(begin,L"-inf", sizeof(L"-inf"));
- end = begin + 4;
- } else
- {
- memcpy(begin,L"inf", sizeof(L"inf"));
- end = begin + 3;
- }
- return true;
- }
 
- return false;
- }
-#endif
         template <class CharT, class T>
         bool put_inf_nan(CharT* begin, CharT*& end, const T& value)
         {
- using namespace std;
- if ( (boost::math::isnan)(value) )
- {
- if ( (boost::math::signbit)(value) )
- {
- memcpy(begin,"-nan", sizeof("-nan"));
- end = begin + 4;
- } else
- {
- memcpy(begin,"nan", sizeof("nan"));
- end = begin + 3;
- }
- return true;
- } else if ( (boost::math::isinf)(value) )
- {
- if ( (boost::math::signbit)(value) )
- {
- memcpy(begin,"-inf", sizeof("-inf"));
- end = begin + 4;
- } else
- {
- memcpy(begin,"inf", sizeof("inf"));
- end = begin + 3;
- }
- return true;
- }
-
- return false;
+ return put_inf_nan_impl(begin, end, value, "nan", "infinity");
         }
-
     }
 
 
@@ -951,7 +953,7 @@
             CharT const capital_e = lcast_char_constants<CharT>::capital_e;
             CharT const lowercase_e = lcast_char_constants<CharT>::lowercase_e;
 
- value = 0.0;
+ value = static_cast<T>(0);
 
             if (parse_inf_nan(begin, end, value)) return true;
 
@@ -1165,7 +1167,7 @@
 
     namespace detail
     {
- struct do_not_construct_stringbuffer_t{};
+ struct do_not_construct_out_stream_t{};
     }
 
     namespace detail // optimized stream wrapper
@@ -1177,25 +1179,27 @@
>
         class lexical_stream_limited_src
         {
- typedef stl_buf_unlocker<std::basic_streambuf<CharT, Traits>, CharT > local_streambuffer_t;
 
 #if defined(BOOST_NO_STRINGSTREAM)
- typedef stl_buf_unlocker<std::strstream, CharT > local_stringbuffer_t;
+ typedef std::ostrstream out_stream_t;
+ typedef stl_buf_unlocker<std::strstreambuf, char> unlocked_but_t;
 #elif defined(BOOST_NO_STD_LOCALE)
- typedef stl_buf_unlocker<std::stringstream, CharT > local_stringbuffer_t;
+ typedef std::ostringstream out_stream_t;
+ typedef stl_buf_unlocker<std::stringbuf, char> unlocked_but_t;
 #else
- typedef stl_buf_unlocker<std::basic_stringbuf<CharT, Traits>, CharT > local_stringbuffer_t;
+ typedef std::basic_ostringstream<CharT, Traits> out_stream_t;
+ typedef stl_buf_unlocker<std::basic_stringbuf<CharT, Traits>, CharT> unlocked_but_t;
 #endif
             typedef BOOST_DEDUCED_TYPENAME ::boost::mpl::if_c<
                 RequiresStringbuffer,
- local_stringbuffer_t,
- do_not_construct_stringbuffer_t
- >::type deduced_stringbuffer_t;
+ out_stream_t,
+ do_not_construct_out_stream_t
+ >::type deduced_out_stream_t;
 
             // A string representation of Source is written to [start, finish).
             CharT* start;
             CharT* finish;
- deduced_stringbuffer_t stringbuffer;
+ deduced_out_stream_t out_stream;
 
         public:
             lexical_stream_limited_src(CharT* sta, CharT* fin)
@@ -1256,10 +1260,16 @@
             template<typename InputStreamable>
             bool shl_input_streamable(InputStreamable& input)
             {
- std::basic_ostream<CharT> stream(&stringbuffer);
- bool const result = !(stream << input).fail();
- start = stringbuffer.pbase();
- finish = stringbuffer.pptr();
+#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
+ // If you have compilation error at this point, than your STL library
+ // unsupports such conversions. Try updating it.
+ BOOST_STATIC_ASSERT((boost::is_same<char, CharT>::value));
+#endif
+ bool const result = !(out_stream << input).fail();
+ const unlocked_but_t* const p
+ = static_cast<unlocked_but_t*>(out_stream.rdbuf()) ;
+ start = p->pbase();
+ finish = p->pptr();
                 return result;
             }
 
@@ -1524,9 +1534,22 @@
                 if(is_pointer<InputStreamable>::value)
                     return false;
 
- local_streambuffer_t bb;
- bb.setg(start, start, finish);
- std::basic_istream<CharT> stream(&bb);
+#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
+ // If you have compilation error at this point, than your STL library
+ // unsupports such conversions. Try updating it.
+ BOOST_STATIC_ASSERT((boost::is_same<char, CharT>::value));
+#endif
+
+#if defined(BOOST_NO_STRINGSTREAM)
+ std::istrstream stream(start, finish - start);
+#elif defined(BOOST_NO_STD_LOCALE)
+ std::istringstream stream;
+#else
+ std::basic_istringstream<CharT, Traits> stream;
+#endif
+ static_cast<unlocked_but_t*>(stream.rdbuf())
+ ->setg(start, start, finish);
+
                 stream.unsetf(std::ios::skipws);
                 lcast_set_precision(stream, static_cast<InputStreamable*>(0));
 #if (defined _MSC_VER)
@@ -1935,52 +1958,52 @@
             }
         };
 
- class precision_loss_error : public boost::numeric::bad_numeric_cast
+ template<class Source, class Target >
+ struct detect_precision_loss
         {
- public:
- virtual const char * what() const throw()
- { return "bad numeric conversion: precision loss error"; }
- };
-
- template<class S >
- struct throw_on_precision_loss
- {
- typedef boost::numeric::Trunc<S> Rounder;
- typedef S source_type ;
+ typedef boost::numeric::Trunc<Source> Rounder;
+ typedef Source source_type ;
 
- typedef typename mpl::if_< is_arithmetic<S>,S,S const&>::type argument_type ;
+ typedef BOOST_DEDUCED_TYPENAME mpl::if_<
+ is_arithmetic<Source>, Source, Source const&
+ >::type argument_type ;
 
          static source_type nearbyint ( argument_type s )
          {
- source_type orig_div_round = s / Rounder::nearbyint(s);
+ const source_type orig_div_round = s / Rounder::nearbyint(s);
+ const source_type eps = std::numeric_limits<source_type>::epsilon();
+
+ if ((orig_div_round > 1 ? orig_div_round - 1 : 1 - orig_div_round) > eps)
+ BOOST_LCAST_THROW_BAD_CAST(Source, Target);
 
- if ( (orig_div_round > 1 ? orig_div_round - 1 : 1 - orig_div_round) > std::numeric_limits<source_type>::epsilon() )
- BOOST_THROW_EXCEPTION( precision_loss_error() );
             return s ;
          }
 
          typedef typename Rounder::round_style round_style;
         } ;
 
+ template<class Source, class Target >
+ struct nothrow_overflow_handler
+ {
+ void operator() ( boost::numeric::range_check_result r )
+ {
+ if (r != boost::numeric::cInRange)
+ BOOST_LCAST_THROW_BAD_CAST(Source, Target);
+ }
+ } ;
+
         template<typename Target, typename Source>
         struct lexical_cast_dynamic_num_not_ignoring_minus
         {
             static inline Target lexical_cast_impl(const Source &arg)
             {
- try{
- typedef boost::numeric::converter<
- Target,
- Source,
- boost::numeric::conversion_traits<Target,Source>,
- boost::numeric::def_overflow_handler,
- throw_on_precision_loss<Source>
- > Converter ;
-
- return Converter::convert(arg);
- } catch( ::boost::numeric::bad_numeric_cast const& ) {
- BOOST_LCAST_THROW_BAD_CAST(Source, Target);
- }
- BOOST_UNREACHABLE_RETURN(static_cast<Target>(0));
+ return boost::numeric::converter<
+ Target,
+ Source,
+ boost::numeric::conversion_traits<Target,Source>,
+ nothrow_overflow_handler<Source, Target>,
+ detect_precision_loss<Source, Target>
+ >::convert(arg);
             }
         };
 
@@ -1989,25 +2012,17 @@
         {
             static inline Target lexical_cast_impl(const Source &arg)
             {
- try{
- typedef boost::numeric::converter<
- Target,
- Source,
- boost::numeric::conversion_traits<Target,Source>,
- boost::numeric::def_overflow_handler,
- throw_on_precision_loss<Source>
- > Converter ;
-
- bool has_minus = ( arg < 0);
- if ( has_minus ) {
- return static_cast<Target>(-Converter::convert(-arg));
- } else {
- return Converter::convert(arg);
- }
- } catch( ::boost::numeric::bad_numeric_cast const& ) {
- BOOST_LCAST_THROW_BAD_CAST(Source, Target);
- }
- BOOST_UNREACHABLE_RETURN(static_cast<Target>(0));
+ typedef boost::numeric::converter<
+ Target,
+ Source,
+ boost::numeric::conversion_traits<Target,Source>,
+ nothrow_overflow_handler<Source, Target>,
+ detect_precision_loss<Source, Target>
+ > converter_t;
+
+ return (
+ arg < 0 ? -converter_t::convert(-arg) : converter_t::convert(arg)
+ );
             }
         };
 

Modified: branches/release/boost/numeric/conversion/converter_policies.hpp
==============================================================================
--- branches/release/boost/numeric/conversion/converter_policies.hpp (original)
+++ branches/release/boost/numeric/conversion/converter_policies.hpp 2012-03-10 02:31:36 EST (Sat, 10 Mar 2012)
@@ -13,6 +13,7 @@
 #include <typeinfo> // for std::bad_cast
 
 #include <boost/config/no_tr1/cmath.hpp> // for std::floor and std::ceil
+#include <boost/throw_exception.hpp>
 
 #include <functional>
 
@@ -158,10 +159,17 @@
 {
   void operator() ( range_check_result r ) // throw(negative_overflow,positive_overflow)
   {
+#ifndef BOOST_NO_EXCEPTIONS
     if ( r == cNegOverflow )
       throw negative_overflow() ;
     else if ( r == cPosOverflow )
            throw positive_overflow() ;
+#else
+ if ( r == cNegOverflow )
+ ::boost::throw_exception(negative_overflow()) ;
+ else if ( r == cPosOverflow )
+ ::boost::throw_exception(positive_overflow()) ;
+#endif
   }
 } ;
 

Modified: branches/release/libs/conversion/doc/lexical_cast.qbk
==============================================================================
--- branches/release/libs/conversion/doc/lexical_cast.qbk (original)
+++ branches/release/libs/conversion/doc/lexical_cast.qbk 2012-03-10 02:31:36 EST (Sat, 10 Mar 2012)
@@ -3,7 +3,7 @@
     [version 1.0]
     [copyright 2000-2005 Kevlin Henney]
     [copyright 2006-2010 Alexander Nasonov]
- [copyright 2011 Antony Polukhin]
+ [copyright 2011-2012 Antony Polukhin]
     [category String and text processing]
     [category Miscellaneous]
     [license
@@ -167,9 +167,22 @@
 `boost::lexical_cast` sees single `wchar_t` character as `unsigned short`. It is not a `boost::lexical_cast` mistake, but a
 limitation of compiler options that you use.
 
+[pre
+]
+
+* [*Question:] Why `boost::lexical_cast<double>("-1.#IND");` throws `boost::bad_lexical_cast`?
+ * [*Answer:] `"-1.#IND"` is a compiler extension, that violates standard. You shall input `"-nan"`, `"nan"`, `"inf"`
+, `"-inf"` (case insensitive) strings to get NaN and Inf values. `boost::lexical_cast<string>` outputs `"-nan"`, `"nan"`,
+`"inf"`, `"-inf"` strings, when has NaN or Inf input values.
+
 [endsect]
 
 [section Changes]
+* [*boost 1.50.0 :]
+
+ * `boost::bad_lexical_cast` exception is now globaly visible and can be catched even if code is compiled with -fvisibility=hidden.
+ * Now it is possible to compile library with disabled exceptions.
+
 * [*boost 1.49.0 :]
   
     * Restored work with typedefed wchar_t (compilation flag /Zc:wchar_t- for Visual Studio).

Added: branches/release/libs/conversion/perf/Jamfile.v2
==============================================================================
--- (empty file)
+++ branches/release/libs/conversion/perf/Jamfile.v2 2012-03-10 02:31:36 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,29 @@
+#==============================================================================
+# Copyright (c) 2012 Antony Polukhin
+#
+# Distributed under the Boost Software License, Version 1.0. (See accompanying
+# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#==============================================================================
+
+# performance tests
+import testing ;
+import path ;
+
+path-constant TEST_DIR : . ;
+
+project performance/test
+ : source-location ./
+ : requirements
+# <library>/boost/chrono//boost_chrono
+# <library>/boost/system//boost_system
+ <link>static
+ <target-os>freebsd:<linkflags>"-lrt"
+ <target-os>linux:<linkflags>"-lrt"
+ <toolset>gcc:<cxxflags>-fvisibility=hidden
+ <toolset>intel-linux:<cxxflags>-fvisibility=hidden
+ <toolset>sun:<cxxflags>-xldscope=hidden
+ : default-build release
+ ;
+
+run performance_test.cpp : $(TEST_DIR) ;
+

Added: branches/release/libs/conversion/perf/performance_test.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/conversion/perf/performance_test.cpp 2012-03-10 02:31:36 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,309 @@
+// (C) Copyright Antony Polukhin 2012.
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/config for most recent version.
+
+//
+// Testing lexical_cast<> performance
+//
+
+#define BOOST_ERROR_CODE_HEADER_ONLY
+#define BOOST_CHRONO_HEADER_ONLY
+
+#include <boost/lexical_cast.hpp>
+#include <boost/chrono.hpp>
+#include <fstream>
+#include <boost/container/string.hpp>
+
+// File to output data
+std::fstream fout;
+
+template <class OutT, class InT>
+static inline void test_lexical(const InT& in_val) {
+ OutT out_val = boost::lexical_cast<OutT>(in_val);
+ (void)out_val;
+}
+
+template <class OutT, class InT>
+static inline void test_ss_constr(const InT& in_val) {
+ OutT out_val;
+ std::stringstream ss;
+ ss << in_val;
+ if (ss.fail()) throw std::logic_error("descr");
+ ss >> out_val;
+ if (ss.fail()) throw std::logic_error("descr");
+}
+
+template <class OutT, class StringStreamT, class InT>
+static inline void test_ss_noconstr(StringStreamT& ss, const InT& in_val) {
+ OutT out_val;
+ ss << in_val; // ss is an instance of std::stringstream
+ if (ss.fail()) throw std::logic_error("descr");
+ ss >> out_val;
+ if (ss.fail()) throw std::logic_error("descr");
+ /* reseting std::stringstream to use it again */
+ ss.str(std::string());
+ ss.clear();
+}
+
+struct structure_sprintf {
+ template <class OutT, class BufferT, class InT>
+ static inline void test(BufferT* buffer, const InT& in_val, const char* const conv) {
+ sprintf(buffer, conv, in_val);
+ OutT out_val(buffer);
+ }
+
+ template <class OutT, class BufferT>
+ static inline void test(BufferT* buffer, const std::string& in_val, const char* const conv) {
+ sprintf(buffer, conv, in_val.c_str());
+ OutT out_val(buffer);
+ }
+};
+
+struct structure_sscanf {
+ template <class OutT, class BufferT, class InT>
+ static inline void test(BufferT* /*buffer*/, const InT& in_val, const char* const conv) {
+ OutT out_val;
+ sscanf(reinterpret_cast<const char*>(in_val), conv, &out_val);
+ }
+
+ template <class OutT, class BufferT>
+ static inline void test(BufferT* /*buffer*/, const std::string& in_val, const char* const conv) {
+ OutT out_val;
+ sscanf(in_val.c_str(), conv, &out_val);
+ }
+};
+
+struct structure_fake {
+ template <class OutT, class BufferT, class InT>
+ static inline void test(BufferT* /*buffer*/, const InT& /*in_val*/, const char* const /*conv*/) {}
+};
+
+static const int fake_test_value = 9999;
+
+template <class T>
+static inline void min_fancy_output(T v1, T v2, T v3, T v4) {
+ const char beg_mark[] = "!!! *";
+ const char end_mark[] = "* !!!";
+ const char no_mark[] = "";
+
+ unsigned int res = 4;
+ if (v1 < v2 && v1 < v3 && v1 < v4) res = 1;
+ if (v2 < v1 && v2 < v3 && v2 < v4) res = 2;
+ if (v3 < v1 && v3 < v2 && v3 < v4) res = 3;
+
+ fout << "[ "
+ << (res == 1 ? beg_mark : no_mark)
+ ;
+
+ if (v1) fout << v1;
+ else fout << "<1";
+
+ fout << (res == 1 ? end_mark : no_mark)
+ << " ][ "
+ << (res == 2 ? beg_mark : no_mark)
+ ;
+
+ if (v2) fout << v2;
+ else fout << "<1";
+
+ fout << (res == 2 ? end_mark : no_mark)
+ << " ][ "
+ << (res == 3 ? beg_mark : no_mark)
+ ;
+
+ if (v3) fout << v3;
+ else fout << "<1";
+
+ fout << (res == 3 ? end_mark : no_mark)
+ << " ][ "
+ << (res == 4 ? beg_mark : no_mark)
+ ;
+
+ if (!v4) fout << "<1";
+ else if (v4 == fake_test_value) fout << "---";
+ else fout << v4;
+
+ fout
+ << (res == 4 ? end_mark : no_mark)
+ << " ]";
+}
+
+template <unsigned int IetartionsCountV, class ToT, class SprintfT, class FromT>
+static inline void perf_test_impl(const FromT& in_val, const char* const conv) {
+
+ typedef boost::chrono::steady_clock test_clock;
+ test_clock::time_point start;
+ typedef boost::chrono::milliseconds duration_t;
+ duration_t lexical_cast_time, ss_constr_time, ss_noconstr_time, printf_time;
+
+ start = test_clock::now();
+ for (unsigned int i = 0; i < IetartionsCountV; ++i) {
+ test_lexical<ToT>(in_val);
+ test_lexical<ToT>(in_val);
+ test_lexical<ToT>(in_val);
+ test_lexical<ToT>(in_val);
+ }
+ lexical_cast_time = boost::chrono::duration_cast<duration_t>(test_clock::now() - start);
+
+
+ start = test_clock::now();
+ for (unsigned int i = 0; i < IetartionsCountV; ++i) {
+ test_ss_constr<ToT>(in_val);
+ test_ss_constr<ToT>(in_val);
+ test_ss_constr<ToT>(in_val);
+ test_ss_constr<ToT>(in_val);
+ }
+ ss_constr_time = boost::chrono::duration_cast<duration_t>(test_clock::now() - start);
+
+ std::stringstream ss;
+ start = test_clock::now();
+ for (unsigned int i = 0; i < IetartionsCountV; ++i) {
+ test_ss_noconstr<ToT>(ss, in_val);
+ test_ss_noconstr<ToT>(ss, in_val);
+ test_ss_noconstr<ToT>(ss, in_val);
+ test_ss_noconstr<ToT>(ss, in_val);
+ }
+ ss_noconstr_time = boost::chrono::duration_cast<duration_t>(test_clock::now() - start);
+
+
+ char buffer[128];
+ start = test_clock::now();
+ for (unsigned int i = 0; i < IetartionsCountV; ++i) {
+ SprintfT::template test<ToT>(buffer, in_val, conv);
+ SprintfT::template test<ToT>(buffer, in_val, conv);
+ SprintfT::template test<ToT>(buffer, in_val, conv);
+ SprintfT::template test<ToT>(buffer, in_val, conv);
+ }
+ printf_time = boost::chrono::duration_cast<duration_t>(test_clock::now() - start);
+
+ min_fancy_output(
+ lexical_cast_time.count(),
+ ss_constr_time.count(),
+ ss_noconstr_time.count(),
+ boost::is_same<SprintfT, structure_fake>::value ? fake_test_value : printf_time.count()
+ );
+}
+
+template <class ToT, class SprintfT, class FromT>
+static inline void perf_test(const std::string& test_name, const FromT& in_val, const char* const conv) {
+ const unsigned int ITERATIONSCOUNT = 100000;
+ fout << " [[ " << test_name << " ]";
+
+ perf_test_impl<ITERATIONSCOUNT/4, ToT, SprintfT>(in_val, conv);
+
+ fout << "]\n";
+}
+
+
+template <class ConverterT>
+void string_like_test_set(const std::string& from) {
+ typedef structure_sscanf ssc_t;
+ ConverterT conv;
+
+ perf_test<char, ssc_t>(from + "->char", conv("c"), "%c");
+ perf_test<signed char, ssc_t>(from + "->signed char", conv("c"), "%hhd");
+ perf_test<unsigned char, ssc_t>(from + "->unsigned char", conv("c"), "%hhu");
+
+ perf_test<int, ssc_t>(from + "->int", conv("100"), "%d");
+ perf_test<short, ssc_t>(from + "->short", conv("100"), "%hd");
+ perf_test<long int, ssc_t>(from + "->long int", conv("100"), "%ld");
+ perf_test<boost::long_long_type, ssc_t>(from + "->long long", conv("100"), "%lld");
+
+ perf_test<unsigned int, ssc_t>(from + "->unsigned int", conv("100"), "%u");
+ perf_test<unsigned short, ssc_t>(from + "->unsigned short", conv("100"), "%hu");
+ perf_test<unsigned long int, ssc_t>(from + "->unsigned long int", conv("100"), "%lu");
+ perf_test<boost::ulong_long_type, ssc_t>(from + "->unsigned long long", conv("100"), "%llu");
+
+ // perf_test<bool, ssc_t>(from + "->bool", conv("1"), "%");
+
+ perf_test<float, ssc_t>(from + "->float", conv("1.123"), "%f");
+ perf_test<double, ssc_t>(from + "->double", conv("1.123"), "%lf");
+ perf_test<long double, ssc_t>(from + "->long double", conv("1.123"), "%Lf");
+
+
+ perf_test<std::string, structure_fake>(from + "->string", conv("string"), "%Lf");
+ perf_test<boost::container::string, structure_fake>(from + "->container::string"
+ , conv("string"), "%Lf");
+
+}
+
+struct to_string_conv {
+ std::string operator()(const char* const c) const {
+ return c;
+ }
+};
+
+struct to_char_conv {
+ const char* operator()(const char* const c) const {
+ return c;
+ }
+};
+
+struct to_uchar_conv {
+ const unsigned char* operator()(const char* const c) const {
+ return reinterpret_cast<const unsigned char*>(c);
+ }
+};
+
+
+struct to_schar_conv {
+ const signed char* operator()(const char* const c) const {
+ return reinterpret_cast<const signed char*>(c);
+ }
+};
+
+int main(int argc, char** argv) {
+ BOOST_ASSERT(argc >= 2);
+ std::string output_path(argv[1]);
+ output_path += "/results.txt";
+ fout.open(output_path.c_str(), std::fstream::in | std::fstream::out | std::fstream::app);
+ BOOST_ASSERT(fout);
+
+ fout << "[section " << BOOST_COMPILER << "]\n"
+ << "[table:id Performance Table ( "<< BOOST_COMPILER << ")\n"
+ << "[[From->To] [lexical_cast] [std::stringstream with construction] "
+ << "[std::stringstream without construction][scanf/printf]]\n";
+
+
+ // From std::string to ...
+ string_like_test_set<to_string_conv>("string");
+
+ // From ... to std::string
+ perf_test<std::string, structure_sprintf>("string->char", 'c', "%c");
+ perf_test<std::string, structure_sprintf>("string->signed char", static_cast<signed char>('c'), "%hhd");
+ perf_test<std::string, structure_sprintf>("string->unsigned char", static_cast<unsigned char>('c'), "%hhu");
+
+ perf_test<std::string, structure_sprintf>("int->string", 100, "%d");
+ perf_test<std::string, structure_sprintf>("short->string", static_cast<short>(100), "%hd");
+ perf_test<std::string, structure_sprintf>("long int->string", 100l, "%ld");
+ perf_test<std::string, structure_sprintf>("long long->string", 100ll, "%lld");
+
+ perf_test<std::string, structure_sprintf>("unsigned int->string", static_cast<unsigned short>(100u), "%u");
+ perf_test<std::string, structure_sprintf>("unsigned short->string", 100u, "%hu");
+ perf_test<std::string, structure_sprintf>("unsigned long int->string", 100ul, "%lu");
+ perf_test<std::string, structure_sprintf>("unsigned long long->string", static_cast<boost::ulong_long_type>(100), "%llu");
+
+ // perf_test<bool, structure_sscanf>("bool->string", std::string("1"), "%");
+
+ perf_test<std::string, structure_sprintf>("float->string", 1.123f, "%f");
+ perf_test<std::string, structure_sprintf>("double->string", 1.123, "%lf");
+ perf_test<std::string, structure_sprintf>("long double->string", 1.123L, "%Lf");
+
+
+ string_like_test_set<to_char_conv>("char*");
+ string_like_test_set<to_uchar_conv>("unsigned char*");
+ string_like_test_set<to_schar_conv>("signed char*");
+
+ perf_test<int, structure_fake>("int->int", 100, "");
+ perf_test<double, structure_fake>("float->double", 100.0f, "");
+ perf_test<signed char, structure_fake>("char->signed char", 'c', "");
+
+ fout << "]\n"
+ << "[endsect]\n\n";
+ return 0;
+}
+
+

Modified: branches/release/libs/conversion/test/Jamfile.v2
==============================================================================
--- branches/release/libs/conversion/test/Jamfile.v2 (original)
+++ branches/release/libs/conversion/test/Jamfile.v2 2012-03-10 02:31:36 EST (Sat, 10 Mar 2012)
@@ -38,5 +38,12 @@
     [ run lexical_cast_pointers_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
     [ compile lexical_cast_typedefed_wchar_test.cpp : <toolset>msvc:<nowchar>on ]
     [ run lexical_cast_typedefed_wchar_test_runtime.cpp ../../test/build//boost_unit_test_framework/<link>static : : : <toolset>msvc:<nowchar>on ]
- ;
-
+ [ run lexical_cast_no_locale_test.cpp ../../test/build//boost_unit_test_framework/<link>static : : : <define>BOOST_NO_STD_LOCALE <define>BOOST_LEXICAL_CAST_ASSUME_C_LOCALE ]
+ [ run lexical_cast_no_exceptions_test.cpp ../../test/build//boost_unit_test_framework/<link>static : : : <define>BOOST_NO_EXCEPTIONS
+ <toolset>gcc-4.3:<cflags>-fno-exceptions
+ <toolset>gcc-4.4:<cflags>-fno-exceptions
+ <toolset>gcc-4.5:<cflags>-fno-exceptions
+ <toolset>gcc-4.6:<cflags>-fno-exceptions
+ ]
+ ;
+

Modified: branches/release/libs/conversion/test/lexical_cast_containers_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_containers_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_containers_test.cpp 2012-03-10 02:31:36 EST (Sat, 10 Mar 2012)
@@ -13,6 +13,7 @@
 #include <boost/container/string.hpp>
 
 void testing_boost_containers_basic_string();
+void testing_boost_containers_string_std_string();
 
 using namespace boost;
 
@@ -21,6 +22,7 @@
     unit_test::test_suite *suite =
         BOOST_TEST_SUITE("Testing boost::lexical_cast with boost::container::string");
     suite->add(BOOST_TEST_CASE(testing_boost_containers_basic_string));
+ suite->add(BOOST_TEST_CASE(testing_boost_containers_string_std_string));
 
     return suite;
 }
@@ -35,4 +37,24 @@
     BOOST_CHECK(1000 == lexical_cast<int>(str));
 }
 
+#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
+#define BOOST_LCAST_NO_WCHAR_T
+#endif
 
+void testing_boost_containers_string_std_string()
+{
+ std::string std_str("std_str");
+ boost::container::string boost_str("boost_str");
+ BOOST_CHECK(boost::lexical_cast<std::string>(boost_str) == "boost_str");
+ BOOST_CHECK(boost::lexical_cast<boost::container::string>(std_str) == "std_str");
+
+#ifndef BOOST_LCAST_NO_WCHAR_T
+ std::wstring std_wstr(L"std_wstr");
+ boost::container::wstring boost_wstr(L"boost_wstr");
+
+ BOOST_CHECK(boost::lexical_cast<std::wstring>(boost_wstr) == L"boost_wstr");
+ BOOST_CHECK(boost::lexical_cast<boost::container::wstring>(std_wstr) == L"std_wstr");
+
+#endif
+
+}

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 2012-03-10 02:31:36 EST (Sat, 10 Mar 2012)
@@ -138,6 +138,19 @@
     BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
 }
 
+
+struct my_string {
+ friend std::ostream &operator<<(std::ostream& sout, my_string const&/* st*/) {
+ return sout << "";
+ }
+};
+
+void test_empty_zero_terminated_string()
+{
+ my_string st;
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(st), std::string());;
+}
+
 unit_test::test_suite *init_unit_test_suite(int, char *[])
 {
     unit_test::test_suite *suite =
@@ -146,6 +159,7 @@
     suite->add(BOOST_TEST_CASE(&test_empty_string));
     suite->add(BOOST_TEST_CASE(&test_empty_user_class));
     suite->add(BOOST_TEST_CASE(&test_empty_vector));
+ suite->add(BOOST_TEST_CASE(&test_empty_zero_terminated_string));
 
     return suite;
 }

Modified: branches/release/libs/conversion/test/lexical_cast_inf_nan_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_inf_nan_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_inf_nan_test.cpp 2012-03-10 02:31:36 EST (Sat, 10 Mar 2012)
@@ -85,6 +85,12 @@
     BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("+infinity") ) );
     BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("+INFINITY") ) );
 
+ BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("iNfiNity") ) );
+ BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("INfinity") ) );
+
+ BOOST_CHECK( is_neg_inf( lexical_cast<test_t>("-inFINITY") ) );
+ BOOST_CHECK( is_neg_inf( lexical_cast<test_t>("-INFINITY") ) );
+
     BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("nan") ) );
     BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("NAN") ) );
 
@@ -94,6 +100,15 @@
     BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("+nan") ) );
     BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("+NAN") ) );
 
+ BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("nAn") ) );
+ BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("NaN") ) );
+
+ BOOST_CHECK( is_neg_nan( lexical_cast<test_t>("-nAn") ) );
+ BOOST_CHECK( is_neg_nan( lexical_cast<test_t>("-NaN") ) );
+
+ BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("+Nan") ) );
+ BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("+nAN") ) );
+
     BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("nan()") ) );
     BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("NAN(some string)") ) );
     BOOST_CHECK_THROW( lexical_cast<test_t>("NAN(some string"), bad_lexical_cast );
@@ -127,6 +142,12 @@
     BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"+infinity") ) );
     BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"+INFINITY") ) );
 
+ BOOST_CHECK( is_neg_inf( lexical_cast<test_t>(L"-infINIty") ) );
+ BOOST_CHECK( is_neg_inf( lexical_cast<test_t>(L"-INFiniTY") ) );
+
+ BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"+inFINIty") ) );
+ BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"+INfinITY") ) );
+
     BOOST_CHECK( is_pos_nan( lexical_cast<test_t>(L"nan") ) );
     BOOST_CHECK( is_pos_nan( lexical_cast<test_t>(L"NAN") ) );
 

Added: branches/release/libs/conversion/test/lexical_cast_no_exceptions_test.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/conversion/test/lexical_cast_no_exceptions_test.cpp 2012-03-10 02:31:36 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,95 @@
+// Unit test for boost::lexical_cast.
+//
+// See http://www.boost.org for most recent version, including documentation.
+//
+// Copyright Antony Polukhin, 2012.
+//
+// Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
+
+#include <boost/config.hpp>
+
+#if defined(__INTEL_COMPILER)
+#pragma warning(disable: 193 383 488 981 1418 1419)
+#elif defined(BOOST_MSVC)
+#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
+#endif
+
+#include <boost/lexical_cast.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/range/iterator_range.hpp>
+
+#ifndef BOOST_NO_EXCEPTIONS
+#error "This test must be compiled with -DBOOST_NO_EXCEPTIONS"
+#endif
+
+bool g_was_exception = false;
+
+namespace boost {
+
+void throw_exception(std::exception const & ) {
+ g_was_exception = true;
+}
+
+}
+
+using namespace boost;
+
+
+struct Escape
+{
+ Escape(){}
+ Escape(const std::string& s)
+ : str_(s)
+ {}
+
+ std::string str_;
+};
+
+inline std::ostream& operator<< (std::ostream& o, const Escape& rhs)
+{
+ return o << rhs.str_;
+}
+
+inline std::istream& operator>> (std::istream& i, Escape& rhs)
+{
+ return i >> rhs.str_;
+}
+
+void test_exceptions_off()
+{
+ Escape v("");
+
+ g_was_exception = false;
+ lexical_cast<char>(v);
+ BOOST_CHECK(g_was_exception);
+
+ g_was_exception = false;
+ lexical_cast<unsigned char>(v);
+ BOOST_CHECK(g_was_exception);
+
+ v = lexical_cast<Escape>(100);
+ BOOST_CHECK_EQUAL(lexical_cast<int>(v), 100);
+ BOOST_CHECK_EQUAL(lexical_cast<unsigned int>(v), 100u);
+
+ v = lexical_cast<Escape>(0.0);
+ BOOST_CHECK_EQUAL(lexical_cast<double>(v), 0.0);
+
+ BOOST_CHECK_EQUAL(lexical_cast<short>(100), 100);
+ BOOST_CHECK_EQUAL(lexical_cast<float>(0.0), 0.0);
+
+ g_was_exception = false;
+ lexical_cast<short>(700000);
+ BOOST_CHECK(g_was_exception);
+}
+
+unit_test::test_suite *init_unit_test_suite(int, char *[])
+{
+ unit_test::test_suite *suite =
+ BOOST_TEST_SUITE("lexical_cast. Testing with BOOST_NO_EXCEPTIONS");
+ suite->add(BOOST_TEST_CASE(&test_exceptions_off));
+
+ return suite;
+}
+

Added: branches/release/libs/conversion/test/lexical_cast_no_locale_test.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/conversion/test/lexical_cast_no_locale_test.cpp 2012-03-10 02:31:36 EST (Sat, 10 Mar 2012)
@@ -0,0 +1,166 @@
+// Unit test for boost::lexical_cast.
+//
+// See http://www.boost.org for most recent version, including documentation.
+//
+// Copyright Antony Polukhin, 2012.
+//
+// Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
+
+#include <boost/config.hpp>
+
+#if defined(__INTEL_COMPILER)
+#pragma warning(disable: 193 383 488 981 1418 1419)
+#elif defined(BOOST_MSVC)
+#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
+#endif
+
+#include <boost/lexical_cast.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/range/iterator_range.hpp>
+
+using namespace boost;
+
+// Testing compilation and some basic usage with BOOST_NO_STD_LOCALE
+// Tests are mainly copyied from lexical_cast_empty_input_test.cpp (something
+// new added to test_empty_3)
+
+#ifndef BOOST_NO_STD_LOCALE
+#error "This test must be compiled with -DBOOST_NO_STD_LOCALE"
+#endif
+
+
+template <class T>
+void do_test_on_empty_input(T& v)
+{
+ 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);
+ BOOST_CHECK_THROW(lexical_cast<long double>(v), bad_lexical_cast);
+ 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_CHECK_THROW(lexical_cast<boost::ulong_long_type>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<boost::long_long_type>(v), bad_lexical_cast);
+#elif defined(BOOST_HAS_MS_INT64)
+ BOOST_CHECK_THROW(lexical_cast<unsigned __int64>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<__int64>(v), bad_lexical_cast);
+#endif
+}
+
+void test_empty_1()
+{
+ boost::iterator_range<char*> v;
+ do_test_on_empty_input(v);
+ BOOST_CHECK_EQUAL(lexical_cast<std::string>(v), std::string());
+ BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
+
+ boost::iterator_range<const char*> cv;
+ do_test_on_empty_input(cv);
+ BOOST_CHECK_EQUAL(lexical_cast<std::string>(cv), std::string());
+ BOOST_CHECK_THROW(lexical_cast<char>(cv), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<unsigned char>(cv), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<signed char>(cv), bad_lexical_cast);
+
+ const boost::iterator_range<const char*> ccv;
+ do_test_on_empty_input(ccv);
+ BOOST_CHECK_EQUAL(lexical_cast<std::string>(ccv), std::string());
+ BOOST_CHECK_THROW(lexical_cast<char>(ccv), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<unsigned char>(ccv), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<signed char>(ccv), bad_lexical_cast);
+}
+
+void test_empty_2()
+{
+ std::string v;
+ do_test_on_empty_input(v);
+ BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
+}
+
+struct Escape
+{
+ Escape(){}
+ Escape(const std::string& s)
+ : str_(s)
+ {}
+
+ std::string str_;
+};
+
+inline std::ostream& operator<< (std::ostream& o, const Escape& rhs)
+{
+ return o << rhs.str_;
+}
+
+inline std::istream& operator>> (std::istream& i, Escape& rhs)
+{
+ return i >> rhs.str_;
+}
+
+void test_empty_3()
+{
+ Escape v("");
+ do_test_on_empty_input(v);
+
+ BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
+
+ v = lexical_cast<Escape>(100);
+ BOOST_CHECK_EQUAL(lexical_cast<int>(v), 100);
+ BOOST_CHECK_EQUAL(lexical_cast<unsigned int>(v), 100u);
+
+ v = lexical_cast<Escape>(0.0);
+ BOOST_CHECK_EQUAL(lexical_cast<double>(v), 0.0);
+}
+
+namespace std {
+inline std::ostream & operator<<(std::ostream & out, const std::vector<long> & v)
+{
+ std::ostream_iterator<long> it(out);
+ std::copy(v.begin(), v.end(), it);
+ assert(out);
+ return out;
+}
+}
+
+void test_empty_4()
+{
+ std::vector<long> v;
+ do_test_on_empty_input(v);
+ BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
+}
+
+
+struct my_string {
+ friend std::ostream &operator<<(std::ostream& sout, my_string const&/* st*/) {
+ return sout << "";
+ }
+};
+
+void test_empty_5()
+{
+ my_string st;
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(st), std::string());;
+}
+
+unit_test::test_suite *init_unit_test_suite(int, char *[])
+{
+ unit_test::test_suite *suite =
+ BOOST_TEST_SUITE("lexical_cast. Testing with BOOST_NO_STD_LOCALE");
+ suite->add(BOOST_TEST_CASE(&test_empty_1));
+ suite->add(BOOST_TEST_CASE(&test_empty_2));
+ suite->add(BOOST_TEST_CASE(&test_empty_3));
+ suite->add(BOOST_TEST_CASE(&test_empty_4));
+ suite->add(BOOST_TEST_CASE(&test_empty_5));
+
+ return suite;
+}
+

Modified: branches/release/libs/conversion/test/lexical_cast_typedefed_wchar_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_typedefed_wchar_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_typedefed_wchar_test.cpp 2012-03-10 02:31:36 EST (Sat, 10 Mar 2012)
@@ -13,12 +13,27 @@
 #include <boost/static_assert.hpp>
 #include <boost/lexical_cast.hpp>
 
+#include <boost/date_time/gregorian/gregorian.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+void parseDate()
+{
+ std::locale locale;
+ boost::date_time::format_date_parser<boost::gregorian::date, wchar_t> parser(L"", locale);
+ boost::date_time::special_values_parser<boost::gregorian::date, wchar_t> svp;
+
+ boost::gregorian::date date = parser.parse_date(L"", L"", svp);
+ (void)date;
+}
+
+
 int main()
 {
 #ifdef BOOST_MSVC
     BOOST_STATIC_ASSERT((boost::is_same<wchar_t, unsigned short>::value));
 #endif
 
+ parseDate();
     return ::boost::lexical_cast<int>(L"1000") == 1000;
 }
 


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