From 7606bd1197e8b097d175639bc0be68833e1ef1df Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 8 Nov 2010 16:07:32 +0000 Subject: [PATCH] stl_tree.h (_Rb_tree<>::_M_erase_aux): Add. 2010-11-08 Paolo Carlini * include/bits/stl_tree.h (_Rb_tree<>::_M_erase_aux): Add. (_Rb_tree<>::erase(iterator)): Fix in C++0x mode to take const_iterator; remove redundant overload in C++03 mode. (_Rb_tree<>::erase(iterator, iterator)): Likewise. * include/bits/stl_map.h (map<>::erase): Adjust. (map<>::insert): Fix signature in C++0x mode. * include/bits/stl_set.h (set<>::erase): Likewise. (set<>::insert): Likewise. * include/bits/stl_multimap.h (multimap<>::erase): Likewise. (multimap<>::insert): Likewise. * include/bits/stl_multiset.h (multiset<>::erase): Likewise. (multiset<>::insert): Fix signature in C++0x mode. * include/profile/set.h: Adjust. * include/profile/multiset.h: Likewise. * include/profile/map.h: Likewise. * include/profile/multimap.h: Likewise. * testsuite/util/exception/safety.h (erase_base, insert_base): Update. From-SVN: r166438 --- libstdc++-v3/ChangeLog | 21 +++ libstdc++-v3/include/bits/stl_map.h | 10 +- libstdc++-v3/include/bits/stl_multimap.h | 14 +- libstdc++-v3/include/bits/stl_multiset.h | 14 +- libstdc++-v3/include/bits/stl_set.h | 14 +- libstdc++-v3/include/bits/stl_tree.h | 175 +++++------------------- libstdc++-v3/include/profile/map.h | 34 ++--- libstdc++-v3/include/profile/multimap.h | 37 ++---- libstdc++-v3/include/profile/multiset.h | 41 ++---- libstdc++-v3/include/profile/set.h | 37 ++---- libstdc++-v3/testsuite/util/exception/safety.h | 176 +++++++++++-------------- 11 files changed, 222 insertions(+), 351 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d9156b1b380..fa9f25e03c8 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,24 @@ +2010-11-08 Paolo Carlini + + * include/bits/stl_tree.h (_Rb_tree<>::_M_erase_aux): Add. + (_Rb_tree<>::erase(iterator)): Fix in C++0x mode to take + const_iterator; remove redundant overload in C++03 mode. + (_Rb_tree<>::erase(iterator, iterator)): Likewise. + * include/bits/stl_map.h (map<>::erase): Adjust. + (map<>::insert): Fix signature in C++0x mode. + * include/bits/stl_set.h (set<>::erase): Likewise. + (set<>::insert): Likewise. + * include/bits/stl_multimap.h (multimap<>::erase): Likewise. + (multimap<>::insert): Likewise. + * include/bits/stl_multiset.h (multiset<>::erase): Likewise. + (multiset<>::insert): Fix signature in C++0x mode. + * include/profile/set.h: Adjust. + * include/profile/multiset.h: Likewise. + * include/profile/map.h: Likewise. + * include/profile/multimap.h: Likewise. + * testsuite/util/exception/safety.h (erase_base, insert_base): + Update. + 2010-11-07 Paolo Carlini * include/profile/unordered_map (unordered_map<>::operator[](_Key&&)): diff --git a/libstdc++-v3/include/bits/stl_map.h b/libstdc++-v3/include/bits/stl_map.h index 5d6a98b75b2..9614a12f106 100644 --- a/libstdc++-v3/include/bits/stl_map.h +++ b/libstdc++-v3/include/bits/stl_map.h @@ -510,7 +510,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) */ void insert(std::initializer_list __list) - { insert (__list.begin(), __list.end()); } + { insert(__list.begin(), __list.end()); } #endif /** @@ -537,7 +537,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * Insertion requires logarithmic time (if the hint is not taken). */ iterator +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + insert(const_iterator __position, const value_type& __x) +#else insert(iterator __position, const value_type& __x) +#endif { return _M_t._M_insert_unique_(__position, __x); } /** @@ -570,7 +574,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * the pointer is the user's responsibility. */ iterator - erase(iterator __position) + erase(const_iterator __position) { return _M_t.erase(__position); } #else /** @@ -619,7 +623,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * in any way. Managing the pointer is the user's responsibility. */ iterator - erase(iterator __first, iterator __last) + erase(const_iterator __first, const_iterator __last) { return _M_t.erase(__first, __last); } #else /** diff --git a/libstdc++-v3/include/bits/stl_multimap.h b/libstdc++-v3/include/bits/stl_multimap.h index 82a80f27eb4..1a01ffecb6a 100644 --- a/libstdc++-v3/include/bits/stl_multimap.h +++ b/libstdc++-v3/include/bits/stl_multimap.h @@ -459,7 +459,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * Insertion requires logarithmic time (if the hint is not taken). */ iterator +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + insert(const_iterator __position, const value_type& __x) +#else insert(iterator __position, const value_type& __x) +#endif { return _M_t._M_insert_equal_(__position, __x); } /** @@ -506,7 +510,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * responsibility. */ iterator - erase(iterator __position) + erase(const_iterator __position) { return _M_t.erase(__position); } #else /** @@ -552,10 +556,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * This function erases a sequence of elements from a %multimap. * Note that this function only erases the elements, and that if * the elements themselves are pointers, the pointed-to memory is not - * touched in any way. Managing the pointer is the user's responsibility. + * touched in any way. Managing the pointer is the user's + * responsibility. */ iterator - erase(iterator __first, iterator __last) + erase(const_iterator __first, const_iterator __last) { return _M_t.erase(__first, __last); } #else // _GLIBCXX_RESOLVE_LIB_DEFECTS @@ -569,7 +574,8 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * This function erases a sequence of elements from a %multimap. * Note that this function only erases the elements, and that if * the elements themselves are pointers, the pointed-to memory is not - * touched in any way. Managing the pointer is the user's responsibility. + * touched in any way. Managing the pointer is the user's + * responsibility. */ void erase(iterator __first, iterator __last) diff --git a/libstdc++-v3/include/bits/stl_multiset.h b/libstdc++-v3/include/bits/stl_multiset.h index cfe849bf79a..20d7f507899 100644 --- a/libstdc++-v3/include/bits/stl_multiset.h +++ b/libstdc++-v3/include/bits/stl_multiset.h @@ -417,7 +417,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * Insertion requires logarithmic time (if the hint is not taken). */ iterator +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + insert(const_iterator __position, const value_type& __x) +#else insert(iterator __position, const value_type& __x) +#endif { return _M_t._M_insert_equal_(__position, __x); } /** @@ -463,7 +467,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * responsibility. */ iterator - erase(iterator __position) + erase(const_iterator __position) { return _M_t.erase(__position); } #else /** @@ -509,10 +513,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * This function erases a sequence of elements from a %multiset. * Note that this function only erases the elements, and that if * the elements themselves are pointers, the pointed-to memory is not - * touched in any way. Managing the pointer is the user's responsibility. + * touched in any way. Managing the pointer is the user's + * responsibility. */ iterator - erase(iterator __first, iterator __last) + erase(const_iterator __first, const_iterator __last) { return _M_t.erase(__first, __last); } #else /** @@ -524,7 +529,8 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * This function erases a sequence of elements from a %multiset. * Note that this function only erases the elements, and that if * the elements themselves are pointers, the pointed-to memory is not - * touched in any way. Managing the pointer is the user's responsibility. + * touched in any way. Managing the pointer is the user's + * responsibility. */ void erase(iterator __first, iterator __last) diff --git a/libstdc++-v3/include/bits/stl_set.h b/libstdc++-v3/include/bits/stl_set.h index ce5bc6c15f2..211b67e1960 100644 --- a/libstdc++-v3/include/bits/stl_set.h +++ b/libstdc++-v3/include/bits/stl_set.h @@ -429,7 +429,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * Insertion requires logarithmic time (if the hint is not taken). */ iterator +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + insert(const_iterator __position, const value_type& __x) +#else insert(iterator __position, const value_type& __x) +#endif { return _M_t._M_insert_unique_(__position, __x); } /** @@ -472,10 +476,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * This function erases an element, pointed to by the given iterator, * from a %set. Note that this function only erases the element, and * that if the element is itself a pointer, the pointed-to memory is not - * touched in any way. Managing the pointer is the user's responsibility. + * touched in any way. Managing the pointer is the user's + * responsibility. */ iterator - erase(iterator __position) + erase(const_iterator __position) { return _M_t.erase(__position); } #else /** @@ -485,7 +490,8 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * This function erases an element, pointed to by the given iterator, * from a %set. Note that this function only erases the element, and * that if the element is itself a pointer, the pointed-to memory is not - * touched in any way. Managing the pointer is the user's responsibility. + * touched in any way. Managing the pointer is the user's + * responsibility. */ void erase(iterator __position) @@ -523,7 +529,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * in any way. Managing the pointer is the user's responsibility. */ iterator - erase(iterator __first, iterator __last) + erase(const_iterator __first, const_iterator __last) { return _M_t.erase(__first, __last); } #else /** diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h index 4e9fdf73b55..b85398de3f3 100644 --- a/libstdc++-v3/include/bits/stl_tree.h +++ b/libstdc++-v3/include/bits/stl_tree.h @@ -702,22 +702,30 @@ _GLIBCXX_BEGIN_NAMESPACE(std) void _M_insert_equal(_InputIterator __first, _InputIterator __last); + private: + void + _M_erase_aux(const_iterator __position); + + void + _M_erase_aux(const_iterator __first, const_iterator __last); + + public: #ifdef __GXX_EXPERIMENTAL_CXX0X__ // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 130. Associative erase should return an iterator. iterator - erase(iterator __position); - - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // DR 130. Associative erase should return an iterator. - const_iterator - erase(const_iterator __position); + erase(const_iterator __position) + { + const_iterator __result = __position; + ++__result; + _M_erase_aux(__position); + return iterator(static_cast<_Link_type> + (const_cast<_Base_ptr>(__result._M_node))); + } #else void - erase(iterator __position); - - void - erase(const_iterator __position); + erase(const_iterator __position) + { _M_erase_aux(__position); } #endif size_type erase(const key_type& __x); @@ -726,18 +734,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 130. Associative erase should return an iterator. iterator - erase(iterator __first, iterator __last); - - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // DR 130. Associative erase should return an iterator. - const_iterator - erase(const_iterator __first, const_iterator __last); + erase(const_iterator __first, const_iterator __last) + { + _M_erase_aux(__first, __last); + return iterator(static_cast<_Link_type> + (const_cast<_Base_ptr>(__last._M_node))); + } #else void - erase(iterator __first, iterator __last); - - void - erase(const_iterator __first, const_iterator __last); + erase(const_iterator __first, const_iterator __last) + { _M_erase_aux(__first, __last); } #endif void erase(const key_type* __first, const key_type* __last); @@ -1353,64 +1359,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _M_insert_equal_(end(), *__first); } -#ifdef __GXX_EXPERIMENTAL_CXX0X__ - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // DR 130. Associative erase should return an iterator. template - typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator - _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: - erase(iterator __position) - { - iterator __result = __position; - ++__result; - _Link_type __y = - static_cast<_Link_type>(_Rb_tree_rebalance_for_erase - (__position._M_node, - this->_M_impl._M_header)); - _M_destroy_node(__y); - --_M_impl._M_node_count; - return __result; - } - - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // DR 130. Associative erase should return an iterator. - template - typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator - _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: - erase(const_iterator __position) - { - const_iterator __result = __position; - ++__result; - _Link_type __y = - static_cast<_Link_type>(_Rb_tree_rebalance_for_erase - (const_cast<_Base_ptr>(__position._M_node), - this->_M_impl._M_header)); - _M_destroy_node(__y); - --_M_impl._M_node_count; - return __result; - } -#else - template - inline void - _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: - erase(iterator __position) - { - _Link_type __y = - static_cast<_Link_type>(_Rb_tree_rebalance_for_erase - (__position._M_node, - this->_M_impl._M_header)); - _M_destroy_node(__y); - --_M_impl._M_node_count; - } - - template - inline void + void _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: - erase(const_iterator __position) + _M_erase_aux(const_iterator __position) { _Link_type __y = static_cast<_Link_type>(_Rb_tree_rebalance_for_erase @@ -1419,68 +1372,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _M_destroy_node(__y); --_M_impl._M_node_count; } -#endif - - template - typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type - _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: - erase(const _Key& __x) - { - pair __p = equal_range(__x); - const size_type __old_size = size(); - erase(__p.first, __p.second); - return __old_size - size(); - } - -#ifdef __GXX_EXPERIMENTAL_CXX0X__ - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // DR 130. Associative erase should return an iterator. - template - typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator - _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: - erase(iterator __first, iterator __last) - { - if (__first == begin() && __last == end()) - { - clear(); - return end(); - } - else - { - while (__first != __last) - erase(__first++); - return __last; - } - } - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // DR 130. Associative erase should return an iterator. - template - typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator - _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: - erase(const_iterator __first, const_iterator __last) - { - if (__first == begin() && __last == end()) - { - clear(); - return end(); - } - else - { - while (__first != __last) - erase(__first++); - return __last; - } - } -#else template void _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: - erase(iterator __first, iterator __last) + _M_erase_aux(const_iterator __first, const_iterator __last) { if (__first == begin() && __last == end()) clear(); @@ -1491,17 +1388,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template - void + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: - erase(const_iterator __first, const_iterator __last) + erase(const _Key& __x) { - if (__first == begin() && __last == end()) - clear(); - else - while (__first != __last) - erase(__first++); + pair __p = equal_range(__x); + const size_type __old_size = size(); + erase(__p.first, __p.second); + return __old_size - size(); } -#endif template diff --git a/libstdc++-v3/include/profile/map.h b/libstdc++-v3/include/profile/map.h index 3f668af176c..5bc9ab9f81b 100644 --- a/libstdc++-v3/include/profile/map.h +++ b/libstdc++-v3/include/profile/map.h @@ -251,17 +251,22 @@ namespace __profile size_type size_before = size(); _Base::insert(__list); __profcxx_map_to_unordered_map_insert(this, size_before, - size() - size_before); + size() - size_before); } #endif iterator +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + insert(const_iterator __position, const value_type& __x) +#else insert(iterator __position, const value_type& __x) +#endif { size_type size_before = size(); - return iterator(_Base::insert(__position, __x)); + iterator __i = iterator(_Base::insert(__position, __x)); __profcxx_map_to_unordered_map_insert(this, size_before, - size() - size_before); + size() - size_before); + return __i; } template @@ -276,7 +281,7 @@ namespace __profile #ifdef __GXX_EXPERIMENTAL_CXX0X__ iterator - erase(iterator __position) + erase(const_iterator __position) { iterator __i = _Base::erase(__position); __profcxx_map_to_unordered_map_erase(this, size(), 1); @@ -306,31 +311,18 @@ namespace __profile #ifdef __GXX_EXPERIMENTAL_CXX0X__ iterator - erase(iterator __first, iterator __last) - { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 151. can't currently clear() empty container - while (__first != __last) - this->erase(__first++); - return __last; - } + erase(const_iterator __first, const_iterator __last) + { return iterator(_Base::erase(__first, __last)); } #else void erase(iterator __first, iterator __last) - { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 151. can't currently clear() empty container - while (__first != __last) - this->erase(__first++); - } + { _Base::erase(__first, __last); } #endif void swap(map& __x) - { - _Base::swap(__x); - } + { _Base::swap(__x); } void clear() diff --git a/libstdc++-v3/include/profile/multimap.h b/libstdc++-v3/include/profile/multimap.h index 2897614050c..6fe7f5bc0d9 100644 --- a/libstdc++-v3/include/profile/multimap.h +++ b/libstdc++-v3/include/profile/multimap.h @@ -192,22 +192,22 @@ namespace __profile #endif iterator +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + insert(const_iterator __position, const value_type& __x) +#else insert(iterator __position, const value_type& __x) - { - return iterator(_Base::insert(__position, __x)); - } +#endif + { return iterator(_Base::insert(__position, __x)); } template void insert(_InputIterator __first, _InputIterator __last) - { - _Base::insert(__first, __last); - } + { _Base::insert(__first, __last); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ iterator - erase(iterator __position) - { return _Base::erase(__position); } + erase(const_iterator __position) + { return iterator(_Base::erase(__position)); } #else void erase(iterator __position) @@ -230,30 +230,17 @@ namespace __profile #ifdef __GXX_EXPERIMENTAL_CXX0X__ iterator - erase(iterator __first, iterator __last) - { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 151. can't currently clear() empty container - while (__first != __last) - this->erase(__first++); - return __last; - } + erase(const_iterator __first, const_iterator __last) + { return iterator(_Base::erase(__first, __last)); } #else void erase(iterator __first, iterator __last) - { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 151. can't currently clear() empty container - while (__first != __last) - this->erase(__first++); - } + { _Base::erase(__first, __last); } #endif void swap(multimap& __x) - { - _Base::swap(__x); - } + { _Base::swap(__x); } void clear() diff --git a/libstdc++-v3/include/profile/multiset.h b/libstdc++-v3/include/profile/multiset.h index 3c113ef88d5..d66fa0cd97c 100644 --- a/libstdc++-v3/include/profile/multiset.h +++ b/libstdc++-v3/include/profile/multiset.h @@ -184,17 +184,17 @@ namespace __profile { return iterator(_Base::insert(__x)); } iterator +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + insert(const_iterator __position, const value_type& __x) +#else insert(iterator __position, const value_type& __x) - { - return iterator(_Base::insert(__position, __x)); - } +#endif + { return iterator(_Base::insert(__position, __x)); } template - void - insert(_InputIterator __first, _InputIterator __last) - { - _Base::insert(__first, __last); - } + void + insert(_InputIterator __first, _InputIterator __last) + { _Base::insert(__first, __last); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ void @@ -204,8 +204,8 @@ namespace __profile #ifdef __GXX_EXPERIMENTAL_CXX0X__ iterator - erase(iterator __position) - { return _Base::erase(__position); } + erase(const_iterator __position) + { return iterator(_Base::erase(__position)); } #else void erase(iterator __position) @@ -228,30 +228,17 @@ namespace __profile #ifdef __GXX_EXPERIMENTAL_CXX0X__ iterator - erase(iterator __first, iterator __last) - { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 151. can't currently clear() empty container - while (__first != __last) - this->erase(__first++); - return __last; - } + erase(const_iterator __first, const_iterator __last) + { return iterator(_Base::erase(__first, __last)); } #else void erase(iterator __first, iterator __last) - { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 151. can't currently clear() empty container - while (__first != __last) - this->erase(__first++); - } + { _Base::erase(__first, __last); } #endif void swap(multiset& __x) - { - _Base::swap(__x); - } + { _Base::swap(__x); } void clear() diff --git a/libstdc++-v3/include/profile/set.h b/libstdc++-v3/include/profile/set.h index 42acf72699a..f6941ebbee9 100644 --- a/libstdc++-v3/include/profile/set.h +++ b/libstdc++-v3/include/profile/set.h @@ -189,17 +189,17 @@ namespace __profile } iterator +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + insert(const_iterator __position, const value_type& __x) +#else insert(iterator __position, const value_type& __x) - { - return iterator(_Base::insert(__position, __x)); - } +#endif + { return iterator(_Base::insert(__position, __x)); } template void insert(_InputIterator __first, _InputIterator __last) - { - _Base::insert(__first, __last); - } + { _Base::insert(__first, __last); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ void @@ -209,8 +209,8 @@ namespace __profile #ifdef __GXX_EXPERIMENTAL_CXX0X__ iterator - erase(iterator __position) - { return _Base::erase(__position); } + erase(const_iterator __position) + { return iterator(_Base::erase(__position)); } #else void erase(iterator __position) @@ -232,30 +232,17 @@ namespace __profile #ifdef __GXX_EXPERIMENTAL_CXX0X__ iterator - erase(iterator __first, iterator __last) - { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 151. can't currently clear() empty container - while (__first != __last) - this->erase(__first++); - return __last; - } + erase(const_iterator __first, const_iterator __last) + { return iterator(_Base::erase(__first, __last)); } #else void erase(iterator __first, iterator __last) - { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 151. can't currently clear() empty container - while (__first != __last) - this->erase(__first++); - } + { _Base::erase(__first, __last); } #endif void swap(set& __x) - { - _Base::swap(__x); - } + { _Base::swap(__x); } void clear() diff --git a/libstdc++-v3/testsuite/util/exception/safety.h b/libstdc++-v3/testsuite/util/exception/safety.h index cab31e22854..9468bffd8d5 100644 --- a/libstdc++-v3/testsuite/util/exception/safety.h +++ b/libstdc++-v3/testsuite/util/exception/safety.h @@ -251,91 +251,93 @@ namespace __gnu_test struct erase_base { typedef typename _Tp::iterator iterator; + typedef typename _Tp::const_iterator const_iterator; - iterator (_Tp::* _F_erase_point)(iterator); - iterator (_Tp::* _F_erase_range)(iterator, iterator); + iterator (_Tp::* _F_erase_point)(const_iterator); + iterator (_Tp::* _F_erase_range)(const_iterator, const_iterator); erase_base() : _F_erase_point(&_Tp::erase), _F_erase_range(&_Tp::erase) { } }; - // Specialization, as forward_list has erase_after. - template - struct erase_base> + // Specializations, old C++03 signatures. + template + struct erase_base> { - typedef std::forward_list<_Tp1, _Tp2> container_type; + typedef std::basic_string<_Tp1, _Tp2, _Tp3> container_type; typedef typename container_type::iterator iterator; - typedef typename container_type::const_iterator const_iterator; - iterator (container_type::* _F_erase_point)(const_iterator); - iterator (container_type::* _F_erase_range)(const_iterator, - const_iterator); + iterator (container_type::* _F_erase_point)(iterator); + iterator (container_type::* _F_erase_range)(iterator, iterator); erase_base() - : _F_erase_point(&container_type::erase_after), - _F_erase_range(&container_type::erase_after) { } + : _F_erase_point(&container_type::erase), + _F_erase_range(&container_type::erase) { } }; - // Specializations for the unordered containers. template - struct erase_base> + template class _Tp4> + struct erase_base<__gnu_cxx::__versa_string<_Tp1, _Tp2, _Tp3, _Tp4>> { - typedef std::unordered_map<_Tp1, _Tp2, _Tp3, _Tp4, _Tp5> + typedef __gnu_cxx::__versa_string<_Tp1, _Tp2, _Tp3, _Tp4> container_type; typedef typename container_type::iterator iterator; - typedef typename container_type::const_iterator const_iterator; - iterator (container_type::* _F_erase_point)(const_iterator); - iterator (container_type::* _F_erase_range)(const_iterator, - const_iterator); + iterator (container_type::* _F_erase_point)(iterator); + iterator (container_type::* _F_erase_range)(iterator, iterator); erase_base() : _F_erase_point(&container_type::erase), _F_erase_range(&container_type::erase) { } }; - template - struct erase_base> + template + struct erase_base> { - typedef std::unordered_multimap<_Tp1, _Tp2, _Tp3, _Tp4, _Tp5> - container_type; + typedef std::deque<_Tp1, _Tp2> container_type; typedef typename container_type::iterator iterator; - typedef typename container_type::const_iterator const_iterator; - iterator (container_type::* _F_erase_point)(const_iterator); - iterator (container_type::* _F_erase_range)(const_iterator, - const_iterator); + iterator (container_type::* _F_erase_point)(iterator); + iterator (container_type::* _F_erase_range)(iterator, iterator); + + erase_base() + : _F_erase_point(&container_type::erase), + _F_erase_range(&container_type::erase) { } + }; + + template + struct erase_base> + { + typedef std::list<_Tp1, _Tp2> container_type; + typedef typename container_type::iterator iterator; + + iterator (container_type::* _F_erase_point)(iterator); + iterator (container_type::* _F_erase_range)(iterator, iterator); erase_base() : _F_erase_point(&container_type::erase), _F_erase_range(&container_type::erase) { } }; - template - struct erase_base> + template + struct erase_base> { - typedef std::unordered_set<_Tp1, _Tp2, _Tp3, _Tp4> - container_type; + typedef std::vector<_Tp1, _Tp2> container_type; typedef typename container_type::iterator iterator; - typedef typename container_type::const_iterator const_iterator; - iterator (container_type::* _F_erase_point)(const_iterator); - iterator (container_type::* _F_erase_range)(const_iterator, - const_iterator); + iterator (container_type::* _F_erase_point)(iterator); + iterator (container_type::* _F_erase_range)(iterator, iterator); erase_base() : _F_erase_point(&container_type::erase), _F_erase_range(&container_type::erase) { } }; - template - struct erase_base> + // Specialization, as forward_list has erase_after. + template + struct erase_base> { - typedef std::unordered_multiset<_Tp1, _Tp2, _Tp3, _Tp4> - container_type; + typedef std::forward_list<_Tp1, _Tp2> container_type; typedef typename container_type::iterator iterator; typedef typename container_type::const_iterator const_iterator; @@ -344,8 +346,8 @@ namespace __gnu_test const_iterator); erase_base() - : _F_erase_point(&container_type::erase), - _F_erase_range(&container_type::erase) { } + : _F_erase_point(&container_type::erase_after), + _F_erase_range(&container_type::erase_after) { } }; template - struct insert_base> + // Specializations, old C++03 signatures. + template + struct insert_base> { - typedef std::basic_string<_Tp1, _Tp2, _Tp3> container_type; + typedef std::deque<_Tp1, _Tp2> container_type; typedef typename container_type::iterator iterator; typedef typename container_type::value_type value_type; - iterator (container_type::* _F_insert_point)(iterator, value_type); + iterator (container_type::* _F_insert_point)(iterator, + const value_type&); insert_base() : _F_insert_point(&container_type::insert) { } }; - template class _Tp4> - struct insert_base<__gnu_cxx::__versa_string<_Tp1, _Tp2, _Tp3, _Tp4>> + template + struct insert_base> { - typedef __gnu_cxx::__versa_string<_Tp1, _Tp2, _Tp3, _Tp4> - container_type; + typedef std::list<_Tp1, _Tp2> container_type; typedef typename container_type::iterator iterator; typedef typename container_type::value_type value_type; - iterator (container_type::* _F_insert_point)(iterator, value_type); + iterator (container_type::* _F_insert_point)(iterator, + const value_type&); insert_base() : _F_insert_point(&container_type::insert) { } }; - // Specialization, as forward_list insertion has a different signature. template - struct insert_base> + struct insert_base> { - typedef std::forward_list<_Tp1, _Tp2> container_type; + typedef std::vector<_Tp1, _Tp2> container_type; typedef typename container_type::iterator iterator; - typedef typename container_type::const_iterator const_iterator; typedef typename container_type::value_type value_type; - iterator (container_type::* _F_insert_point)(const_iterator, - const value_type&); - - insert_base() : _F_insert_point(&container_type::insert_after) { } - }; - - // Likewise for the unordered containers. - template - struct insert_base> - { - typedef std::unordered_map<_Tp1, _Tp2, _Tp3, _Tp4, _Tp5> - container_type; - typedef typename container_type::iterator iterator; - typedef typename container_type::const_iterator const_iterator; - typedef typename container_type::value_type value_type; - - iterator (container_type::* _F_insert_point)(const_iterator, + iterator (container_type::* _F_insert_point)(iterator, const value_type&); insert_base() : _F_insert_point(&container_type::insert) { } }; - template - struct insert_base> + // Specialization, as string insertion has a different signature. + template + struct insert_base> { - typedef std::unordered_multimap<_Tp1, _Tp2, _Tp3, _Tp4, _Tp5> - container_type; + typedef std::basic_string<_Tp1, _Tp2, _Tp3> container_type; typedef typename container_type::iterator iterator; - typedef typename container_type::const_iterator const_iterator; typedef typename container_type::value_type value_type; - iterator (container_type::* _F_insert_point)(const_iterator, - const value_type&); + iterator (container_type::* _F_insert_point)(iterator, value_type); insert_base() : _F_insert_point(&container_type::insert) { } }; - template - struct insert_base> + // Likewise for __versa_string. + template class _Tp4> + struct insert_base<__gnu_cxx::__versa_string<_Tp1, _Tp2, _Tp3, _Tp4>> { - typedef std::unordered_set<_Tp1, _Tp2, _Tp3, _Tp4> + typedef __gnu_cxx::__versa_string<_Tp1, _Tp2, _Tp3, _Tp4> container_type; typedef typename container_type::iterator iterator; - typedef typename container_type::const_iterator const_iterator; typedef typename container_type::value_type value_type; - iterator (container_type::* _F_insert_point)(const_iterator, - const value_type&); + iterator (container_type::* _F_insert_point)(iterator, value_type); insert_base() : _F_insert_point(&container_type::insert) { } }; - template - struct insert_base> + // Specialization, as forward_list has insert_after. + template + struct insert_base> { - typedef std::unordered_multiset<_Tp1, _Tp2, _Tp3, _Tp4> - container_type; + typedef std::forward_list<_Tp1, _Tp2> container_type; typedef typename container_type::iterator iterator; typedef typename container_type::const_iterator const_iterator; typedef typename container_type::value_type value_type; @@ -743,7 +723,7 @@ namespace __gnu_test iterator (container_type::* _F_insert_point)(const_iterator, const value_type&); - insert_base() : _F_insert_point(&container_type::insert) { } + insert_base() : _F_insert_point(&container_type::insert_after) { } }; template