You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2005/09/20 01:20:36 UTC

svn commit: r290303 - /incubator/stdcxx/trunk/include/string

Author: sebor
Date: Mon Sep 19 16:20:32 2005
New Revision: 290303

URL: http://svn.apache.org/viewcvs?rev=290303&view=rev
Log:
2005-09-19  Martin Sebor  <se...@roguewave.com>

	STDCXX-25
	* string (insert): Added overloads for string::const_pointer
	to detect insertion of (substrings of) self.


Modified:
    incubator/stdcxx/trunk/include/string

Modified: incubator/stdcxx/trunk/include/string
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/include/string?rev=290303&r1=290302&r2=290303&view=diff
==============================================================================
--- incubator/stdcxx/trunk/include/string (original)
+++ incubator/stdcxx/trunk/include/string Mon Sep 19 16:20:32 2005
@@ -3,7 +3,7 @@
  *
  * <string> - definition of the C++ Standard Library basic_string template
  *
- * $Id: //stdlib/dev/include/string#99 $
+ * $Id$
  *
  ***************************************************************************
  *
@@ -410,44 +410,61 @@
 
     template<class _InputIter>
     void insert (iterator __p, _InputIter __first, _InputIter __last) {
-        // resolves to insert (iterator, size_type, value_type)
-        // if _InputIter is any integral type (even not an exact match,
-        // such as char)
-        // the cast to int is necessary to avoid an exact match
         insert (__p, __first, __last, _RWSTD_DISPATCH (_InputIter));
     }
 
-    void insert (iterator __p, const_iterator __first, const_iterator __last) {
-        iterator __begin = _C_make_iter (_C_data);
-        iterator __end   = _C_make_iter (_C_data + size ());
+    template <class _InputIter>
+    void insert (iterator __p, _InputIter __first, _InputIter __last, void*) {
+        // unnamed arg is used for overload resolution
+        // _RWSTD_COMPILE_ASSERT (sizeof (*__first));
+        replace (__p, __p, __first, __last);
+    }
+
+    void insert (iterator __p, size_type __n, value_type __c, int) {
+        // unnamed arg is used for overload resolution
+        replace (__p - _C_make_iter (_C_data), size_type (), __n, __c);
+    }
+
+    void insert (iterator __p,
+                 const_pointer __first, const_pointer __last, void*) {
+        // unnamed arg is used for overload resolution
+        const iterator __begin = _C_make_iter (_C_data);
         _RWSTD_ASSERT_RANGE (__begin, __p);
-        if (__first >= __begin && __first <= __end)
+        if (__first >= _C_data && __first <= _C_data + size ())
             insert (__p - __begin, basic_string (__first, __last));
         else
             replace (__p, __p, __first, __last);
     }
 
-    void insert (iterator __p, iterator __first, iterator __last) {
-        insert (__p, const_iterator (__first), const_iterator (__last));
-    }
+#  ifndef _RWSTD_NO_DEBUG_ITER
 
-    template <class _InputIter>
-    void insert (iterator __p, _InputIter __first, _InputIter __last, void*) {
+    void insert (iterator __p,
+                 const_iterator __first, const_iterator __last, void*) {
         // unnamed arg is used for overload resolution
-        // _RWSTD_COMPILE_ASSERT (sizeof (*__first));
-        replace (__p, __p, __first, __last);
+        if (!(__first == __last)) {
+            const const_pointer __pf = &*__first;
+            insert (__p, __pf, __pf + (__last - __first));
+        }
     }
 
-    void insert (iterator __p, size_type __n, value_type __c, int) {
+    void insert (iterator __p, iterator __first, iterator __last, void*) {
         // unnamed arg is used for overload resolution
-        replace (__p - _C_make_iter (_C_data), size_type (), __n, __c);
+        insert (__p, const_iterator (__first), const_iterator (__last),
+                (void*)0);
     }
 
+#  endif   // _RWSTD_NO_DEBUG_ITER
+
 #else   // if defined (_RWSTD_NO_INLINE_MEMBER_TEMPLATES)
 
     void insert (iterator __p, const_pointer __first, const_pointer __last) {
-        replace (__p - _C_make_iter (_C_data), size_type (), __first,
-                 __last - __first);
+        // unnamed arg is used for overload resolution
+        const iterator __begin = _C_make_iter (_C_data);
+        _RWSTD_ASSERT_RANGE (__begin, __p);
+        if (__first >= _C_data && __first <= _C_data + size ())
+            insert (__p - __begin, basic_string (__first, __last));
+        else
+            replace (__p, __p, __first, __last);
     }
 
 #endif  // _RWSTD_NO_INLINE_MEMBER_TEMPLATES