From e2825ab72984890e0fb658089320b117961c3513 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Thu, 13 Mar 2003 17:27:06 +0000 Subject: [PATCH] overloading fix + less permissive wide character support [SVN r17893] --- include/boost/lexical_cast.hpp | 29 +++++++++++++++++++---------- lexical_cast_test.cpp | 22 ++++++++++------------ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/include/boost/lexical_cast.hpp b/include/boost/lexical_cast.hpp index 820e4d1..3a248f1 100644 --- a/include/boost/lexical_cast.hpp +++ b/include/boost/lexical_cast.hpp @@ -1,16 +1,16 @@ #ifndef BOOST_LEXICAL_CAST_INCLUDED #define BOOST_LEXICAL_CAST_INCLUDED -// boost lexical_cast.hpp header --------------------------------------------// - -// See http://www.boost.org/libs/conversion for documentation. +// Boost lexical_cast.hpp header -------------------------------------------// +// +// See http://www.boost.org for most recent version including documentation. // See end of this header for rights and permissions. // // what: lexical_cast custom keyword cast // who: contributed by Kevlin Henney, // enhanced with contributions from Terje Slettebų, // with additional fixes and suggestions from Gennaro Prota, -// Dave Abrahams, Daryle Walker, and other Boosters on the list +// Beman Dawes, Dave Abrahams, Daryle Walker, and other Boosters // when: November 2000, March 2003 #include @@ -25,6 +25,12 @@ #include #endif +#if defined(BOOST_NO_STRINGSTREAM) || \ + defined(BOOST_NO_STD_WSTRING) || \ + defined(BOOST_NO_INTRINSIC_WCHAR_T) +#define DISABLE_WIDE_CHAR_SUPPORT +#endif + namespace boost { // exception used to indicate runtime lexical_cast failure @@ -69,7 +75,7 @@ namespace boost typedef char type; }; - #ifndef BOOST_NO_STRINGSTREAM + #ifndef DISABLE_WIDE_CHAR_SUPPORT template<> struct stream_char { @@ -88,7 +94,6 @@ namespace boost typedef wchar_t type; }; - #ifndef BOOST_NO_STD_WSTRING template<> struct stream_char { @@ -96,8 +101,6 @@ namespace boost }; #endif - #endif - template struct widest_char { @@ -143,11 +146,16 @@ namespace boost stream >> output && (stream >> std::ws).eof(); } - template - bool operator>>(std::basic_string &output) + bool operator>>(std::string &output) { return std::getline(stream, output, char_type()).eof(); } + #ifndef DISABLE_WIDE_CHAR_SUPPORT + bool operator>>(std::wstring &output) + { + return std::getline(stream, output, char_type()).eof(); + } + #endif private: typedef typename widest_char< typename stream_char::type, @@ -181,4 +189,5 @@ namespace boost // // This software is provided "as is" without express or implied warranty. +#undef DISABLE_WIDE_CHAR_SUPPORT #endif diff --git a/lexical_cast_test.cpp b/lexical_cast_test.cpp index 1d3c631..8fe79bb 100644 --- a/lexical_cast_test.cpp +++ b/lexical_cast_test.cpp @@ -22,11 +22,10 @@ #include #include -// If BOOST_NO_STRINGSTREAM is defined wide character support is unavailable, -// and all wide character tests are disabled. - -#ifdef BOOST_NO_STRINGSTREAM -#define NO_WIDE_CHAR_SUPPORT +#if defined(BOOST_NO_STRINGSTREAM) || \ + defined(BOOST_NO_STD_WSTRING) || \ + defined(BOOST_NO_INTRINSIC_WCHAR_T) +#define DISABLE_WIDE_CHAR_SUPPORT #endif using namespace boost; @@ -52,7 +51,7 @@ unit_test_framework::test_suite *init_unit_test_suite(int, char **) suite->add(BOOST_TEST_CASE(test_conversion_to_bool)); suite->add(BOOST_TEST_CASE(test_conversion_to_pointer)); suite->add(BOOST_TEST_CASE(test_conversion_to_string)); - #ifndef NO_WIDE_CHAR_SUPPORT + #ifndef DISABLE_WIDE_CHAR_SUPPORT suite->add(BOOST_TEST_CASE(test_conversion_from_wchar_t)); suite->add(BOOST_TEST_CASE(test_conversion_to_wchar_t)); suite->add(BOOST_TEST_CASE(test_conversion_from_wstring)); @@ -175,7 +174,6 @@ void test_conversion_to_bool() void test_conversion_to_string() { - // *** All the following gives compilation error (ambiguity) on MSVC 6 BOOST_CHECK_EQUAL("A", lexical_cast('A')); BOOST_CHECK_EQUAL(" ", lexical_cast(' ')); BOOST_CHECK_EQUAL("123", lexical_cast(123)); @@ -197,14 +195,14 @@ void test_conversion_to_string() void test_conversion_to_pointer() { BOOST_CHECK_THROW(lexical_cast("Test"), boost::bad_lexical_cast); - #ifndef NO_WIDE_CHAR_SUPPORT + #ifndef DISABLE_WIDE_CHAR_SUPPORT BOOST_CHECK_THROW(lexical_cast("Test"), boost::bad_lexical_cast); #endif } void test_conversion_from_wchar_t() { - #ifndef NO_WIDE_CHAR_SUPPORT + #ifndef DISABLE_WIDE_CHAR_SUPPORT BOOST_CHECK_EQUAL(1, lexical_cast(L'1')); BOOST_CHECK_THROW(lexical_cast(L'A'), boost::bad_lexical_cast); @@ -241,7 +239,7 @@ void test_conversion_from_wchar_t() void test_conversion_to_wchar_t() { - #ifndef NO_WIDE_CHAR_SUPPORT + #ifndef DISABLE_WIDE_CHAR_SUPPORT BOOST_CHECK_EQUAL(L'1', lexical_cast(1)); BOOST_CHECK_EQUAL(L'0', lexical_cast(0)); BOOST_CHECK_THROW(lexical_cast(123), boost::bad_lexical_cast); @@ -270,7 +268,7 @@ void test_conversion_to_wchar_t() void test_conversion_from_wstring() { - #ifndef NO_WIDE_CHAR_SUPPORT + #ifndef DISABLE_WIDE_CHAR_SUPPORT BOOST_CHECK_EQUAL(123, lexical_cast(std::wstring(L"123"))); BOOST_CHECK_THROW( lexical_cast(std::wstring(L"")), boost::bad_lexical_cast); @@ -294,7 +292,7 @@ void test_conversion_from_wstring() void test_conversion_to_wstring() { - #ifndef NO_WIDE_CHAR_SUPPORT + #ifndef DISABLE_WIDE_CHAR_SUPPORT BOOST_CHECK(L"123" == lexical_cast(123)); BOOST_CHECK(L"1.23" == lexical_cast(1.23)); BOOST_CHECK(L"1.111111111" == lexical_cast(1.111111111));