$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r74940 - in trunk: boost libs/conversion/test
From: antoshkka_at_[hidden]
Date: 2011-10-13 14:36:40
Author: apolukhin
Date: 2011-10-13 14:36:39 EDT (Thu, 13 Oct 2011)
New Revision: 74940
URL: http://svn.boost.org/trac/boost/changeset/74940
Log:
Performance optimizations and testsfor conversions to/from boost::container::basic_string
Added:
   trunk/libs/conversion/test/lexical_cast_containers_test.cpp   (contents, props changed)
Text files modified: 
   trunk/boost/lexical_cast.hpp          |    63 ++++++++++++++++++++++++++++++++++++++++
   trunk/libs/conversion/test/Jamfile.v2 |     1                                         
   2 files changed, 64 insertions(+), 0 deletions(-)
Modified: trunk/boost/lexical_cast.hpp
==============================================================================
--- trunk/boost/lexical_cast.hpp	(original)
+++ trunk/boost/lexical_cast.hpp	2011-10-13 14:36:39 EDT (Thu, 13 Oct 2011)
@@ -46,6 +46,7 @@
 #include <boost/static_assert.hpp>
 #include <boost/detail/lcast_precision.hpp>
 #include <boost/detail/workaround.hpp>
+#include <boost/container/container_fwd.hpp>
 #include <cwchar>
 
 
@@ -145,6 +146,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 +266,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 +292,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
     }
 
@@ -1257,6 +1291,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;
@@ -1462,6 +1504,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 +1643,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 +1749,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: trunk/libs/conversion/test/Jamfile.v2
==============================================================================
--- trunk/libs/conversion/test/Jamfile.v2	(original)
+++ trunk/libs/conversion/test/Jamfile.v2	2011-10-13 14:36:39 EDT (Thu, 13 Oct 2011)
@@ -28,6 +28,7 @@
     [ 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 ]
   ;
 
       
Added: trunk/libs/conversion/test/lexical_cast_containers_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/conversion/test/lexical_cast_containers_test.cpp	2011-10-13 14:36:39 EDT (Thu, 13 Oct 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));
+}
+
+