diff options
Diffstat (limited to 'libstdc++-v3/include/debug/deque')
-rw-r--r-- | libstdc++-v3/include/debug/deque | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/libstdc++-v3/include/debug/deque b/libstdc++-v3/include/debug/deque index 9c21598ea67..cf63c3af090 100644 --- a/libstdc++-v3/include/debug/deque +++ b/libstdc++-v3/include/debug/deque @@ -47,14 +47,17 @@ namespace __debug typedef _GLIBCXX_STD_D::deque<_Tp, _Allocator> _Base; typedef __gnu_debug::_Safe_sequence<deque> _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: typedef typename _Base::reference reference; typedef typename _Base::const_reference const_reference; - typedef __gnu_debug::_Safe_iterator<typename _Base::iterator,deque> + typedef __gnu_debug::_Safe_iterator<_Base_iterator,deque> iterator; - typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator,deque> - const_iterator; + typedef __gnu_debug::_Safe_iterator<_Base_const_iterator,deque> + const_iterator; typedef typename _Base::size_type size_type; typedef typename _Base::difference_type difference_type; @@ -219,6 +222,15 @@ namespace __debug { return const_reverse_iterator(begin()); } #endif + private: + void + _M_invalidate_after_nth(difference_type __n) + { + typedef __gnu_debug::_After_nth_from<_Base_const_iterator> _After_nth; + this->_M_invalidate_if(_After_nth(__n, _Base::begin())); + } + + public: // 23.2.1.2 capacity: using _Base::size; using _Base::max_size; @@ -227,12 +239,9 @@ namespace __debug void resize(size_type __sz) { - typedef typename _Base::const_iterator _Base_const_iterator; - typedef __gnu_debug::_After_nth_from<_Base_const_iterator> _After_nth; - bool __invalidate_all = __sz > this->size(); if (__sz < this->size()) - this->_M_invalidate_if(_After_nth(__sz, _M_base().begin())); + this->_M_invalidate_after_nth(__sz); _Base::resize(__sz); @@ -243,12 +252,9 @@ namespace __debug void resize(size_type __sz, const _Tp& __c) { - typedef typename _Base::const_iterator _Base_const_iterator; - typedef __gnu_debug::_After_nth_from<_Base_const_iterator> _After_nth; - bool __invalidate_all = __sz > this->size(); if (__sz < this->size()) - this->_M_invalidate_if(_After_nth(__sz, _M_base().begin())); + this->_M_invalidate_after_nth(__sz); _Base::resize(__sz, __c); @@ -259,12 +265,9 @@ namespace __debug void resize(size_type __sz, _Tp __c = _Tp()) { - typedef typename _Base::const_iterator _Base_const_iterator; - typedef __gnu_debug::_After_nth_from<_Base_const_iterator> _After_nth; - bool __invalidate_all = __sz > this->size(); if (__sz < this->size()) - this->_M_invalidate_if(_After_nth(__sz, _M_base().begin())); + this->_M_invalidate_after_nth(__sz); _Base::resize(__sz, __c); @@ -369,8 +372,8 @@ namespace __debug emplace(iterator __position, _Args&&... __args) { __glibcxx_check_insert(__position); - typename _Base::iterator __res = _Base::emplace(__position.base(), - std::forward<_Args>(__args)...); + _Base_iterator __res = _Base::emplace(__position.base(), + std::forward<_Args>(__args)...); this->_M_invalidate_all(); return iterator(__res, this); } @@ -380,7 +383,7 @@ namespace __debug insert(iterator __position, const _Tp& __x) { __glibcxx_check_insert(__position); - typename _Base::iterator __res = _Base::insert(__position.base(), __x); + _Base_iterator __res = _Base::insert(__position.base(), __x); this->_M_invalidate_all(); return iterator(__res, this); } @@ -421,8 +424,7 @@ namespace __debug pop_front() { __glibcxx_check_nonempty(); - iterator __victim = begin(); - __victim._M_invalidate(); + this->_M_invalidate_if(_Equal(_Base::begin())); _Base::pop_front(); } @@ -430,9 +432,7 @@ namespace __debug pop_back() { __glibcxx_check_nonempty(); - iterator __victim = end(); - --__victim; - __victim._M_invalidate(); + this->_M_invalidate_if(_Equal(--_Base::end())); _Base::pop_back(); } @@ -440,14 +440,15 @@ namespace __debug erase(iterator __position) { __glibcxx_check_erase(__position); - if (__position == begin() || __position == end()-1) + _Base_iterator __victim = __position.base(); + if (__victim == _Base::begin() || __victim == _Base::end()-1) { - __position._M_invalidate(); - return iterator(_Base::erase(__position.base()), this); + this->_M_invalidate_if(_Equal(__victim)); + return iterator(_Base::erase(__victim), this); } else { - typename _Base::iterator __res = _Base::erase(__position.base()); + _Base_iterator __res = _Base::erase(__victim); this->_M_invalidate_all(); return iterator(__res, this); } @@ -459,13 +460,13 @@ namespace __debug // _GLIBCXX_RESOLVE_LIB_DEFECTS // 151. can't currently clear() empty container __glibcxx_check_erase_range(__first, __last); - if (__first == begin() || __last == end()) + if (__first.base() == _Base::begin() || __last.base() == _Base::end()) { this->_M_detach_singular(); - for (iterator __position = __first; __position != __last; ) + for (_Base_iterator __position = __first.base(); + __position != __last.base(); ++__position) { - iterator __victim = __position++; - __victim._M_invalidate(); + this->_M_invalidate_if(_Equal(__position)); } __try { @@ -480,8 +481,8 @@ namespace __debug } else { - typename _Base::iterator __res = _Base::erase(__first.base(), - __last.base()); + _Base_iterator __res = _Base::erase(__first.base(), + __last.base()); this->_M_invalidate_all(); return iterator(__res, this); } |