aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/debug/multiset.h
diff options
context:
space:
mode:
authorfdumont <fdumont@138bc75d-0d04-0410-961f-82ee72b054a4>2010-11-25 20:53:39 +0000
committerfdumont <fdumont@138bc75d-0d04-0410-961f-82ee72b054a4>2010-11-25 20:53:39 +0000
commit8e9bca591d9307979fde531663fb4d34da242aae (patch)
tree655bd05d685adc6a2c1cc45fb794a00e1ae25b76 /libstdc++-v3/include/debug/multiset.h
parent39bf7c517034933b46170285a64bafbd95cf0861 (diff)
2010-11-25 François Dumont <francois.cppdevs@free.fr>
* src/debug.cc: Introduce a mutex pool in get_safe_base_mutex. Move code used to manipulate sequence safe iterators from safe iterator methods to safe sequence ones. Remove usage of safe iterator mutex, keep _Safe_iterator_base::_M_get_mutex for library backward binary compatibility. * src/Makefile.am: Build debug.cc in gnu++0x mode for _Hash_impl usage. * src/Makefile.in: Regenerate * include/debug/safe_base.h: Add _Safe_iterator_base _M_invalidate and _M_reset. Add _Safe_sequence_base _M_attach, _M_attach_single, _M_detach and _M_detach_single. * include/debug.safe_iterator.h, safe_iterator.tcc: Remove _Safe_iterator _M_invalidate and _M_invalidate_single. Implement all methods in terms of normal iterators rather than safe ones. * include/debug/safe_sequence.h: Replace _Safe_sequence _M_transfe_iter with _M_transfer_from_if taking the source sequence and a predicate signaling when a safe iterator shall be transfered. Add _Equal_to predicate. * include/debug/safe_sequence.tcc: New. * include/Makefile.am: Adjust. * include/Makefile.in: Regenerate. * include/debug/forward_list: Swap safe iterators in move constructor. Do not invalidate before begin in _M_invalidate_all method. Reimplement safe methods using normal iterators rather than safe ones. * include/debug/set.h, unordered_map, multiset.h, vector, unordered_set, deque, map.h, list, multimap.h: Reimplement safe method using normal iterators rather than safe ones. * testsuite/23_containers/forward_list/debug/clear.cc, swap.cc, move_constructor.cc, splice_after.cc, splice_after1.cc, splice_after2.cc, splice_after3.cc, splice_after4.cc: New. * testsuite/23_containers/vector/debug/multithreaded_swap.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@167152 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/debug/multiset.h')
-rw-r--r--libstdc++-v3/include/debug/multiset.h69
1 files changed, 44 insertions, 25 deletions
diff --git a/libstdc++-v3/include/debug/multiset.h b/libstdc++-v3/include/debug/multiset.h
index 9c950a1d0c2..8462586b844 100644
--- a/libstdc++-v3/include/debug/multiset.h
+++ b/libstdc++-v3/include/debug/multiset.h
@@ -48,6 +48,9 @@ namespace __debug
typedef _GLIBCXX_STD_D::multiset<_Key, _Compare, _Allocator> _Base;
typedef __gnu_debug::_Safe_sequence<multiset> _Safe_base;
+ typedef typename _Base::const_iterator _Base_const_iterator;
+ typedef typename _Base::iterator _Base_iterator;
+ typedef __gnu_debug::_Equal_to<_Base_const_iterator> _Equal;
public:
// types:
typedef _Key key_type;
@@ -58,9 +61,9 @@ namespace __debug
typedef typename _Base::reference reference;
typedef typename _Base::const_reference const_reference;
- typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, multiset>
+ typedef __gnu_debug::_Safe_iterator<_Base_iterator, multiset>
iterator;
- typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator,
+ typedef __gnu_debug::_Safe_iterator<_Base_const_iterator,
multiset> const_iterator;
typedef typename _Base::size_type size_type;
@@ -237,7 +240,7 @@ namespace __debug
erase(const_iterator __position)
{
__glibcxx_check_erase(__position);
- __position._M_invalidate();
+ this->_M_invalidate_if(_Equal(__position.base()));
return iterator(_Base::erase(__position.base()), this);
}
#else
@@ -245,7 +248,7 @@ namespace __debug
erase(iterator __position)
{
__glibcxx_check_erase(__position);
- __position._M_invalidate();
+ this->_M_invalidate_if(_Equal(__position.base()));
_Base::erase(__position.base());
}
#endif
@@ -253,15 +256,16 @@ namespace __debug
size_type
erase(const key_type& __x)
{
- std::pair<iterator, iterator> __victims = this->equal_range(__x);
+ std::pair<_Base_iterator, _Base_iterator> __victims =
+ _Base::equal_range(__x);
size_type __count = 0;
- while (__victims.first != __victims.second)
- {
- iterator __victim = __victims.first++;
- __victim._M_invalidate();
- _Base::erase(__victim.base());
- ++__count;
- }
+ _Base_iterator __victim = __victims.first;
+ while (__victim != __victims.second)
+ {
+ this->_M_invalidate_if(_Equal(__victim));
+ _Base::erase(__victim++);
+ ++__count;
+ }
return __count;
}
@@ -272,9 +276,16 @@ namespace __debug
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 151. can't currently clear() empty container
__glibcxx_check_erase_range(__first, __last);
- while (__first != __last)
- this->erase(__first++);
- return __last; // iterator == const_iterator
+ for (_Base_const_iterator __victim = __first.base();
+ __victim != __last.base(); ++__victim)
+ {
+ _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
+ _M_message(__gnu_debug::__msg_valid_range)
+ ._M_iterator(__first, "first")
+ ._M_iterator(__last, "last"));
+ this->_M_invalidate_if(_Equal(__victim));
+ }
+ return iterator(_Base::erase(__first.base(), __last.base()), this);
}
#else
void
@@ -283,8 +294,16 @@ namespace __debug
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 151. can't currently clear() empty container
__glibcxx_check_erase_range(__first, __last);
- while (__first != __last)
- this->erase(__first++);
+ for (_Base_iterator __victim = __first.base();
+ __victim != __last.base(); ++__victim)
+ {
+ _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
+ _M_message(__gnu_debug::__msg_valid_range)
+ ._M_iterator(__first, "first")
+ ._M_iterator(__last, "last"));
+ this->_M_invalidate_if(_Equal(__victim));
+ }
+ _Base::erase(__first.base(), __last.base());
}
#endif
@@ -297,7 +316,10 @@ namespace __debug
void
clear()
- { this->erase(begin(), end()); }
+ {
+ this->_M_invalidate_all();
+ _Base::clear();
+ }
// observers:
using _Base::key_comp;
@@ -339,9 +361,8 @@ namespace __debug
std::pair<iterator,iterator>
equal_range(const key_type& __x)
{
- typedef typename _Base::iterator _Base_iterator;
std::pair<_Base_iterator, _Base_iterator> __res =
- _Base::equal_range(__x);
+ _Base::equal_range(__x);
return std::make_pair(iterator(__res.first, this),
iterator(__res.second, this));
}
@@ -351,9 +372,8 @@ namespace __debug
std::pair<const_iterator,const_iterator>
equal_range(const key_type& __x) const
{
- typedef typename _Base::const_iterator _Base_iterator;
- std::pair<_Base_iterator, _Base_iterator> __res =
- _Base::equal_range(__x);
+ std::pair<_Base_const_iterator, _Base_const_iterator> __res =
+ _Base::equal_range(__x);
return std::make_pair(const_iterator(__res.first, this),
const_iterator(__res.second, this));
}
@@ -368,9 +388,8 @@ namespace __debug
void
_M_invalidate_all()
{
- typedef typename _Base::const_iterator _Base_const_iterator;
typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
- this->_M_invalidate_if(_Not_equal(_M_base().end()));
+ this->_M_invalidate_if(_Not_equal(_Base::end()));
}
};