stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From far...@apache.org
Subject svn commit: r507971 - /incubator/stdcxx/trunk/include/list
Date Thu, 15 Feb 2007 15:48:09 GMT
Author: faridz
Date: Thu Feb 15 07:48:09 2007
New Revision: 507971

URL: http://svn.apache.org/viewvc?view=rev&rev=507971
Log:
2007-02-15 Farid Zaripov <faridz@kyiv.vdiweb.com>

	STDCXX-268
	STDCXX-331
	* list (_RWSTD_LIST_SAFE_INSERT_RANGE): New macro for exception
	safe inserting the range into the list.
	(_C_insert (bidirectional_iterator_tag, input_iterator_tag)):
	Removed.
	(_C_insert): Used _RWSTD_LIST_SAFE_INSERT_RANGE macro.
	(_C_insert): Added try/catch with removing the inserted elements
	if exception was thrown.

Modified:
    incubator/stdcxx/trunk/include/list

Modified: incubator/stdcxx/trunk/include/list
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/include/list?view=diff&rev=507971&r1=507970&r2=507971
==============================================================================
--- incubator/stdcxx/trunk/include/list (original)
+++ incubator/stdcxx/trunk/include/list Thu Feb 15 07:48:09 2007
@@ -344,6 +344,25 @@
 
 #endif // _RWSTD_NO_LIST_NODE_BUFFER
 
+#  define _RWSTD_LIST_SAFE_INSERT_RANGE(__it, __first, __last)  \
+    _RWSTD_ASSERT_RANGE (begin (), __it);                       \
+    _RWSTD_ASSERT_RANGE (__first, __last);                      \
+                                                                \
+    if (!(__first == __last)) {                                 \
+        iterator __start = __it;                                \
+                                                                \
+        _TRY {                                                  \
+            __start = insert (__it, *__first);                  \
+                                                                \
+            while (!(++__first == __last))                      \
+                insert (__it, *__first);                        \
+        } _CATCH (...) {                                        \
+            erase (__start, __it);                              \
+            _RETHROW;                                           \
+        }                                                       \
+    } typedef void __dummy_t
+
+
     // here and only here is _C_node initialized
     void _C_init (bool __empty_list = false) {
         _C_node = _C_get_node (__empty_list);
@@ -572,37 +591,12 @@
 #if !defined (_RWSTD_NO_INLINE_MEMBER_TEMPLATES)  \
     && (!defined (_MSC_VER) || _MSC_VER >= 1300)
 
-    // handles bidirectional iterators
-    template <class _InputIterator>
-    void _C_insert (const iterator &__it,
-                    _InputIterator __first, _InputIterator __last, 
-                    bidirectional_iterator_tag) {
-        _RWSTD_ASSERT_RANGE (begin (), __it);
-        _RWSTD_ASSERT_RANGE (__first, __last);
-
-        for ( ; !(__first == __last); ++__first)
-            insert (__it, *__first); 
-    }
-
-    // handles input iterators
-    template <class _InputIterator>
-    void _C_insert (iterator __it,
-                    _InputIterator __first, _InputIterator __last, 
-                    input_iterator_tag) {
-        _RWSTD_ASSERT_RANGE (begin (), __it);
-        _RWSTD_ASSERT_RANGE (__first, __last);
-
-        for ( ; !(__first == __last); ++__first, ++__it)
-            __it = insert (__it, *__first); 
-    }
- 
     // handles nonintegral types
     template<class _InputIterator>
     void _C_insert (const iterator &__it,
                     _InputIterator  __first, _InputIterator __last, void*) {
 
-        _C_insert (__it, __first, __last, 
-		   _RWSTD_ITERATOR_CATEGORY (_InputIterator, __first));
+        _RWSTD_LIST_SAFE_INSERT_RANGE (__it, __first, __last);
     }
 
     // handles integral types
@@ -643,20 +637,12 @@
     }
 
     void insert (iterator __it, const_pointer __first, const_pointer __last) {
-        _RWSTD_ASSERT_RANGE (begin (), __it);
-        _RWSTD_ASSERT_RANGE (__first, __last);
-
-        for (; !(__first == __last); ++__first)
-            insert (__it, *__first);
+        _RWSTD_LIST_SAFE_INSERT_RANGE (__it, __first, __last);
     }
 
     void insert (iterator __it,
                  const_iterator __first, const_iterator __last) {
-        _RWSTD_ASSERT_RANGE (begin (), __it);
-        _RWSTD_ASSERT_RANGE (__first, __last);
-
-        for (; !(__first == __last); ++__first)
-            insert (__it, *__first);
+        _RWSTD_LIST_SAFE_INSERT_RANGE (__it, __first, __last);
     }
 
 #endif   // _RWSTD_NO_INLINE_MEMBER_TEMPLATES
@@ -706,8 +692,19 @@
     void _C_insert (iterator __it, size_type __n, const_reference __x) {
         _RWSTD_ASSERT_RANGE (begin (), __it);
 
-        while (__n--)
-            insert (__it, __x);
+        if (__n) {
+            iterator __start = __it;
+
+            _TRY {
+                __start = insert (__it, __x);
+
+                while (--__n)
+                    insert (__it, __x);
+            } _CATCH (...) {
+                erase (__start, __it);
+                _RETHROW;
+            }
+        }
     }
 
 public:



Mime
View raw message