diff options
Diffstat (limited to 'libstdc++-v3/include/debug/set.h')
-rw-r--r-- | libstdc++-v3/include/debug/set.h | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/libstdc++-v3/include/debug/set.h b/libstdc++-v3/include/debug/set.h index b8ff463b2cf..60fbd38f26b 100644 --- a/libstdc++-v3/include/debug/set.h +++ b/libstdc++-v3/include/debug/set.h @@ -48,6 +48,9 @@ namespace __debug typedef _GLIBCXX_STD_D::set<_Key, _Compare, _Allocator> _Base; typedef __gnu_debug::_Safe_sequence<set> _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, set> + typedef __gnu_debug::_Safe_iterator<_Base_iterator, set> iterator; - typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator, set> + typedef __gnu_debug::_Safe_iterator<_Base_const_iterator, set> const_iterator; typedef typename _Base::size_type size_type; @@ -193,7 +196,6 @@ namespace __debug std::pair<iterator, bool> insert(const value_type& __x) { - typedef typename _Base::iterator _Base_iterator; std::pair<_Base_iterator, bool> __res = _Base::insert(__x); return std::pair<iterator, bool>(iterator(__res.first, this), __res.second); @@ -248,7 +250,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 @@ -256,7 +258,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 @@ -264,15 +266,15 @@ namespace __debug size_type erase(const key_type& __x) { - iterator __victim = find(__x); - if (__victim == end()) + _Base_iterator __victim = _Base::find(__x); + if (__victim == _Base::end()) return 0; else - { - __victim._M_invalidate(); - _Base::erase(__victim.base()); - return 1; - } + { + this->_M_invalidate_if(_Equal(__victim)); + _Base::erase(__victim); + return 1; + } } #ifdef __GXX_EXPERIMENTAL_CXX0X__ @@ -282,9 +284,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 @@ -293,8 +302,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 @@ -307,7 +324,10 @@ namespace __debug void clear() - { this->erase(begin(), end()); } + { + this->_M_invalidate_all(); + _Base::clear(); + } // observers: using _Base::key_comp; @@ -349,7 +369,6 @@ 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); return std::make_pair(iterator(__res.first, this), @@ -361,7 +380,6 @@ 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); return std::make_pair(const_iterator(__res.first, this), @@ -378,7 +396,6 @@ 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())); } |