|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r76062 - in branches/release: boost libs/conversion libs/conversion/doc libs/conversion/test
From: antoshkka_at_[hidden]
Date: 2011-12-19 10:19:45
Author: apolukhin
Date: 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
New Revision: 76062
URL: http://svn.boost.org/trac/boost/changeset/76062
Log:
Merge from trunk r75937
* fixed a lot of wchar_t errors
* Optimizations for boost::containers::basic_string
* More tests
Added:
branches/release/libs/conversion/test/lexical_cast_containers_test.cpp (contents, props changed)
branches/release/libs/conversion/test/lexical_cast_typedefed_wchar_test.cpp (contents, props changed)
branches/release/libs/conversion/test/lexical_cast_typedefed_wchar_test_runtime.cpp (contents, props changed)
Text files modified:
branches/release/boost/lexical_cast.hpp | 90 ++++++++++++++++++++++++++++++++++++---
branches/release/libs/conversion/doc/lexical_cast.qbk | 12 +++++
branches/release/libs/conversion/lexical_cast_test.cpp | 2
branches/release/libs/conversion/test/Jamfile.v2 | 9 +++
branches/release/libs/conversion/test/lexical_cast_abstract_test.cpp | 2
branches/release/libs/conversion/test/lexical_cast_empty_input_test.cpp | 2
branches/release/libs/conversion/test/lexical_cast_float_types_test.cpp | 2
branches/release/libs/conversion/test/lexical_cast_inf_nan_test.cpp | 2
branches/release/libs/conversion/test/lexical_cast_loopback_test.cpp | 2
branches/release/libs/conversion/test/lexical_cast_noncopyable_test.cpp | 2
branches/release/libs/conversion/test/lexical_cast_vc8_bug_test.cpp | 2
branches/release/libs/conversion/test/lexical_cast_wchars_test.cpp | 2
12 files changed, 111 insertions(+), 18 deletions(-)
Modified: branches/release/boost/lexical_cast.hpp
==============================================================================
--- branches/release/boost/lexical_cast.hpp (original)
+++ branches/release/boost/lexical_cast.hpp 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -17,7 +17,8 @@
// enhanced with contributions from Terje Slettebo,
// with additional fixes and suggestions from Gennaro Prota,
// Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
-// Alexander Nasonov, Antony Polukhin and other Boosters
+// Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
+// Cheng Yang and other Boosters
// when: November 2000, March 2003, June 2005, June 2006, March 2011
#include <climits>
@@ -46,8 +47,10 @@
#include <boost/static_assert.hpp>
#include <boost/detail/lcast_precision.hpp>
#include <boost/detail/workaround.hpp>
-#include <cwchar>
-
+#include <boost/container/container_fwd.hpp>
+#ifndef BOOST_NO_CWCHAR
+# include <cwchar>
+#endif
#ifndef BOOST_NO_STD_LOCALE
# include <locale>
@@ -145,6 +148,12 @@
{
typedef CharT type;
};
+
+ template<class CharT, class Traits, class Alloc>
+ struct stream_char< ::boost::container::basic_string<CharT,Traits,Alloc> >
+ {
+ typedef CharT type;
+ };
#endif
#ifndef BOOST_LCAST_NO_WCHAR_T
@@ -259,6 +268,24 @@
typedef Traits type;
};
+ template<class CharT, class Traits, class Alloc, class Source>
+ struct deduce_char_traits< CharT
+ , ::boost::container::basic_string<CharT,Traits,Alloc>
+ , Source
+ >
+ {
+ typedef Traits type;
+ };
+
+ template<class CharT, class Target, class Traits, class Alloc>
+ struct deduce_char_traits< CharT
+ , Target
+ , ::boost::container::basic_string<CharT,Traits,Alloc>
+ >
+ {
+ typedef Traits type;
+ };
+
template<class CharT, class Traits, class Alloc1, class Alloc2>
struct deduce_char_traits< CharT
, std::basic_string<CharT,Traits,Alloc1>
@@ -267,6 +294,15 @@
{
typedef Traits type;
};
+
+ template<class CharT, class Traits, class Alloc1, class Alloc2>
+ struct deduce_char_traits< CharT
+ , ::boost::container::basic_string<CharT,Traits,Alloc1>
+ , ::boost::container::basic_string<CharT,Traits,Alloc2>
+ >
+ {
+ typedef Traits type;
+ };
#endif
}
@@ -648,8 +684,8 @@
, const CharT opening_brace, const CharT closing_brace)
{
using namespace std;
- const wchar_t minus = lcast_char_constants<wchar_t>::minus;
- const wchar_t plus = lcast_char_constants<wchar_t>::plus;
+ const CharT minus = lcast_char_constants<CharT>::minus;
+ const CharT plus = lcast_char_constants<CharT>::plus;
const int inifinity_size = 8;
bool has_minus = false;
@@ -1257,6 +1293,14 @@
return true;
}
+ template<class Alloc>
+ bool operator<<(::boost::container::basic_string<CharT,Traits,Alloc> const& str)
+ {
+ start = const_cast<CharT*>(str.data());
+ finish = start + str.length();
+ return true;
+ }
+
bool operator<<(bool value)
{
CharT const czero = lcast_char_constants<CharT>::zero;
@@ -1310,6 +1354,7 @@
/************************************ HELPER FUNCTIONS FOR OPERATORS >> ( ... ) ********************************/
private:
+
template <typename Type>
bool shr_unsigned(Type& output)
{
@@ -1436,7 +1481,7 @@
}
/************************************ OPERATORS >> ( ... ) ********************************/
- public:
+ public:
bool operator>>(unsigned short& output) { return shr_unsigned(output); }
bool operator>>(unsigned int& output) { return shr_unsigned(output); }
bool operator>>(unsigned long int& output) { return shr_unsigned(output); }
@@ -1449,11 +1494,19 @@
#elif defined(BOOST_HAS_MS_INT64)
bool operator>>(unsigned __int64& output) { return shr_unsigned(output); }
bool operator>>(__int64& output) { return shr_signed(output); }
-
#endif
- bool operator>>(CharT& output) { return shr_xchar(output); }
+ bool operator>>(char& output) { return shr_xchar(output); }
bool operator>>(unsigned char& output) { return shr_xchar(output); }
bool operator>>(signed char& output) { return shr_xchar(output); }
+#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
+ bool operator>>(wchar_t& output) { return shr_xchar(output); }
+#endif
+#ifndef BOOST_NO_CHAR16_T
+ bool operator>>(char16_t& output) { return shr_xchar(output); }
+#endif
+#ifndef BOOST_NO_CHAR32_T
+ bool operator>>(char32_t& output) { return shr_xchar(output); }
+#endif
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
bool operator>>(std::string& str) { str.assign(start, finish); return true; }
# ifndef BOOST_LCAST_NO_WCHAR_T
@@ -1462,6 +1515,9 @@
#else
template<class Alloc>
bool operator>>(std::basic_string<CharT,Traits,Alloc>& str) { str.assign(start, finish); return true; }
+
+ template<class Alloc>
+ bool operator>>(::boost::container::basic_string<CharT,Traits,Alloc>& str) { str.assign(start, finish); return true; }
#endif
/*
* case "-0" || "0" || "+0" : output = false; return true;
@@ -1598,6 +1654,12 @@
BOOST_STATIC_CONSTANT(bool, value = true );
};
+ template<typename CharT, typename Traits, typename Alloc>
+ struct is_stdstring< ::boost::container::basic_string<CharT, Traits, Alloc> >
+ {
+ BOOST_STATIC_CONSTANT(bool, value = true );
+ };
+
template<typename T>
struct is_char_or_wchar
{
@@ -1698,6 +1760,18 @@
BOOST_STATIC_CONSTANT(bool, value = true );
};
+ template<typename CharT, typename Traits, typename Alloc>
+ struct is_char_array_to_stdstring< ::boost::container::basic_string<CharT, Traits, Alloc>, CharT* >
+ {
+ BOOST_STATIC_CONSTANT(bool, value = true );
+ };
+
+ template<typename CharT, typename Traits, typename Alloc>
+ struct is_char_array_to_stdstring< ::boost::container::basic_string<CharT, Traits, Alloc>, const CharT* >
+ {
+ BOOST_STATIC_CONSTANT(bool, value = true );
+ };
+
#if (defined _MSC_VER)
# pragma warning( push )
# pragma warning( disable : 4701 ) // possible use of ... before initialization
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 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -159,9 +159,21 @@
the rules of `scanf` for conversions. And in the C99 standard for unsigned input value minus sign is optional, so
if a negative number is read, no errors will arise and the result will be the two's complement.
+[pre
+]
+
+* [*Question:] Why `boost::lexical_cast<int>(L'A');` outputs 65 and `boost::lexical_cast<wchar_t>(L"65");` does not throw?
+ * [*Answer:] If you are using an old version of Visual Studio or compile code with /Zc:wchar_t- flag,
+`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.
+
[endsect]
[section Changes]
+* [*boost 1.49.0 :]
+
+ * Added code to work with typedefed wchar_t (compilation flag /Zc:wchar_t- for Visual Studio).
+
* [*boost 1.48.0 :]
* Added code to work with Inf and NaN on any platform.
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 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -110,7 +110,7 @@
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
- unit_test_framework::test_suite *suite =
+ unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast unit test");
suite->add(BOOST_TEST_CASE(test_conversion_to_char));
suite->add(BOOST_TEST_CASE(test_conversion_to_int));
Modified: branches/release/libs/conversion/test/Jamfile.v2
==============================================================================
--- branches/release/libs/conversion/test/Jamfile.v2 (original)
+++ branches/release/libs/conversion/test/Jamfile.v2 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -14,7 +14,12 @@
# bring in rules for testing
import testing ;
+import feature ;
+feature.feature nowchar : on :
+ composite optional propagated link-incompatible ;
+feature.compose <nowchar>on : <cxxflags>/Zc:wchar_t- ;
+
test-suite conversion
: [ run implicit_cast.cpp ]
[ compile-fail implicit_cast_fail.cpp ]
@@ -28,7 +33,9 @@
[ run lexical_cast_wchars_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
[ run lexical_cast_float_types_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
[ run lexical_cast_inf_nan_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
+ [ run lexical_cast_containers_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
[ run lexical_cast_empty_input_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 ]
;
-
Modified: branches/release/libs/conversion/test/lexical_cast_abstract_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_abstract_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_abstract_test.cpp 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -28,7 +28,7 @@
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
- unit_test_framework::test_suite *suite =
+ unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast unit test");
suite->add(BOOST_TEST_CASE(&test_abstract));
Added: branches/release/libs/conversion/test/lexical_cast_containers_test.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/conversion/test/lexical_cast_containers_test.cpp 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -0,0 +1,38 @@
+// Testing boost::lexical_cast with boost::container::string.
+//
+// See http://www.boost.org for most recent version, including documentation.
+//
+// Copyright Antony Polukhin, 2011.
+//
+// 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/lexical_cast.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/container/string.hpp>
+
+void testing_boost_containers_basic_string();
+
+using namespace boost;
+
+boost::unit_test::test_suite *init_unit_test_suite(int, char *[])
+{
+ 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));
+
+ return suite;
+}
+
+void testing_boost_containers_basic_string()
+{
+ BOOST_CHECK("100" == lexical_cast<boost::container::string>("100"));
+ BOOST_CHECK(L"100" == lexical_cast<boost::container::wstring>(L"100"));
+
+ BOOST_CHECK("100" == lexical_cast<boost::container::string>(100));
+ boost::container::string str("1000");
+ BOOST_CHECK(1000 == lexical_cast<int>(str));
+}
+
+
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 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -49,7 +49,7 @@
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
- unit_test_framework::test_suite *suite =
+ unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast. Empty input unit test");
suite->add(BOOST_TEST_CASE(&test_empty_iterator_range));
suite->add(BOOST_TEST_CASE(&test_empty_string));
Modified: branches/release/libs/conversion/test/lexical_cast_float_types_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_float_types_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_float_types_test.cpp 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -31,7 +31,7 @@
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
- unit_test_framework::test_suite *suite =
+ unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast float types unit test");
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_float));
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_double));
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 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -170,7 +170,7 @@
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
- unit_test_framework::test_suite *suite =
+ unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast inf anf nan parsing unit test");
suite->add(BOOST_TEST_CASE(&test_inf_nan_float));
suite->add(BOOST_TEST_CASE(&test_inf_nan_double));
Modified: branches/release/libs/conversion/test/lexical_cast_loopback_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_loopback_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_loopback_test.cpp 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -30,7 +30,7 @@
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
- unit_test_framework::test_suite *suite =
+ unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast unit test");
suite->add(BOOST_TEST_CASE(&test_round_conversion_float));
suite->add(BOOST_TEST_CASE(&test_round_conversion_double));
Modified: branches/release/libs/conversion/test/lexical_cast_noncopyable_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_noncopyable_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_noncopyable_test.cpp 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -28,7 +28,7 @@
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
- unit_test_framework::test_suite *suite =
+ unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast unit test");
suite->add(BOOST_TEST_CASE(&test_noncopyable));
Added: branches/release/libs/conversion/test/lexical_cast_typedefed_wchar_test.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/conversion/test/lexical_cast_typedefed_wchar_test.cpp 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -0,0 +1,25 @@
+// Unit test for boost::lexical_cast.
+//
+// See http://www.boost.org for most recent version, including documentation.
+//
+// Copyright Antony Polukhin, 2011.
+//
+// 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>
+
+#include <boost/static_assert.hpp>
+#include <boost/lexical_cast.hpp>
+
+int main()
+{
+#ifdef BOOST_MSVC
+ BOOST_STATIC_ASSERT((boost::is_same<wchar_t, unsigned short>::value));
+#endif
+
+ return ::boost::lexical_cast<int>(L"1000") == 1000;
+}
+
+
Added: branches/release/libs/conversion/test/lexical_cast_typedefed_wchar_test_runtime.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/conversion/test/lexical_cast_typedefed_wchar_test_runtime.cpp 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -0,0 +1,48 @@
+// Unit test for boost::lexical_cast.
+//
+// See http://www.boost.org for most recent version, including documentation.
+//
+// Copyright Antony Polukhin, 2011.
+//
+// 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>
+using namespace boost;
+
+void test_typedefed_wchar_t_runtime()
+{
+#ifndef BOOST_LCAST_NO_WCHAR_T
+#ifdef BOOST_MSVC
+ BOOST_STATIC_ASSERT((boost::is_same<wchar_t, unsigned short>::value));
+
+
+ BOOST_CHECK_EQUAL(boost::lexical_cast<int>(L'A'), 65);
+ BOOST_CHECK_EQUAL(boost::lexical_cast<int>(L'B'), 66);
+
+ BOOST_CHECK_EQUAL(boost::lexical_cast<wchar_t>(L"65"), 65);
+ BOOST_CHECK_EQUAL(boost::lexical_cast<wchar_t>(L"66"), 66);
+#endif
+#endif
+ BOOST_CHECK(1);
+}
+
+unit_test::test_suite *init_unit_test_suite(int, char *[])
+{
+ unit_test::test_suite *suite =
+ BOOST_TEST_SUITE("lexical_cast typedefed wchar_t runtime test");
+ suite->add(BOOST_TEST_CASE(&test_typedefed_wchar_t_runtime));
+
+ return suite;
+}
Modified: branches/release/libs/conversion/test/lexical_cast_vc8_bug_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_vc8_bug_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_vc8_bug_test.cpp 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -60,7 +60,7 @@
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
- unit_test_framework::test_suite *suite =
+ unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast vc8 bug unit test");
suite->add(BOOST_TEST_CASE(test_vc8_bug));
return suite;
Modified: branches/release/libs/conversion/test/lexical_cast_wchars_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_wchars_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_wchars_test.cpp 2011-12-19 10:19:43 EST (Mon, 19 Dec 2011)
@@ -48,7 +48,7 @@
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
- unit_test_framework::test_suite *suite =
+ unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast char<->wchar_t unit test");
suite->add(BOOST_TEST_CASE(&test_char_types_conversions));
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