Commit 7606bd11 by Paolo Carlini Committed by Paolo Carlini

stl_tree.h (_Rb_tree<>::_M_erase_aux): Add.

2010-11-08  Paolo Carlini  <paolo.carlini@oracle.com>

	* 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
parent 7876e2b5
2010-11-08 Paolo Carlini <paolo.carlini@oracle.com>
* 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 <paolo.carlini@oracle.com>
* include/profile/unordered_map (unordered_map<>::operator[](_Key&&)):
......
......@@ -510,7 +510,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
*/
void
insert(std::initializer_list<value_type> __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
/**
......
......@@ -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)
......
......@@ -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)
......
......@@ -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
/**
......
......@@ -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 _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc>
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 _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc>
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<typename _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc>
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<typename _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc>
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 _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc>
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
erase(const _Key& __x)
{
pair<iterator, iterator> __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 _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc>
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 _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc>
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<typename _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc>
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<typename _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc>
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<iterator, iterator> __p = equal_range(__x);
const size_type __old_size = size();
erase(__p.first, __p.second);
return __old_size - size();
}
#endif
template<typename _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc>
......
......@@ -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<typename _InputIterator>
......@@ -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()
......
......@@ -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<typename _InputIterator>
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()
......
......@@ -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<typename _InputIterator>
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()
......
......@@ -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 <typename _InputIterator>
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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment