From 3188147e09e857c04e462487e35721b908d35a37 Mon Sep 17 00:00:00 2001 From: fdumont Date: Fri, 8 Nov 2013 21:03:58 +0000 Subject: [PATCH] =?utf8?q?2013-11-08=20=20Fran=C3=A7ois=20Dumont=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * include/debug/safe_iterator.h (_BeforeBeginHelper<>::_S_Is): Take only a const safe iterator reference. (_BeforeBeginHelper<>::_S_Is_beginnest): Likewise. (__get_distance): Take only one type of iterator. (_Safe_iterator<>::_M_valid_range<>): Not template anymore. (_Safe_iterator<>::_M_get_sequence()): Return pointer to const sequence from a const_iterator and a pointer to sequence from an iterator. * include/debug/safe_iterator.tcc: Adapt. * include/debug/safe_local_iterator.h (_Safe_local_iterator<>::_M_valid_range<>): Not template anymore. (_Safe_local_iterator<>::_M_get_sequence()): Return pointer to const sequence from a const_iterator and a pointer to sequence from an iterator. * include/debug/safe_local_iterator.tcc: Adapt. * include/debug/forward_list (_BeforeBeginHelper>): Adapt. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@204598 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 20 ++++++ libstdc++-v3/include/debug/forward_list | 21 +++--- libstdc++-v3/include/debug/safe_iterator.h | 79 +++++++++++----------- libstdc++-v3/include/debug/safe_iterator.tcc | 72 +++++++++----------- libstdc++-v3/include/debug/safe_local_iterator.h | 19 +++--- libstdc++-v3/include/debug/safe_local_iterator.tcc | 49 +++++++------- 6 files changed, 139 insertions(+), 121 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 3ecd3ba..31bffa5 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,23 @@ +2013-11-08 François Dumont + + * include/debug/safe_iterator.h (_BeforeBeginHelper<>::_S_Is): + Take only a const safe iterator reference. + (_BeforeBeginHelper<>::_S_Is_beginnest): Likewise. + (__get_distance): Take only one type of iterator. + (_Safe_iterator<>::_M_valid_range<>): Not template anymore. + (_Safe_iterator<>::_M_get_sequence()): Return pointer to const + sequence from a const_iterator and a pointer to sequence from an + iterator. + * include/debug/safe_iterator.tcc: Adapt. + * include/debug/safe_local_iterator.h + (_Safe_local_iterator<>::_M_valid_range<>): Not template anymore. + (_Safe_local_iterator<>::_M_get_sequence()): Return pointer to + const sequence from a const_iterator and a pointer to sequence + from an iterator. + * include/debug/safe_local_iterator.tcc: Adapt. + * include/debug/forward_list + (_BeforeBeginHelper>): Adapt. + 2013-11-08 Jonathan Wakely * include/bits/regex_automaton.h (__detail::_State): Split diff --git a/libstdc++-v3/include/debug/forward_list b/libstdc++-v3/include/debug/forward_list index 4c8ac37..5269f39 100644 --- a/libstdc++-v3/include/debug/forward_list +++ b/libstdc++-v3/include/debug/forward_list @@ -785,23 +785,26 @@ namespace __gnu_debug struct _BeforeBeginHelper > { typedef std::__debug::forward_list<_Tp, _Alloc> _Sequence; - typedef typename _Sequence::const_iterator _It; - typedef typename _It::iterator_type _BaseIt; - static bool - _S_Is(_BaseIt __it, const _Sequence* __seq) - { return __it == __seq->_M_base().cbefore_begin(); } + template + static bool + _S_Is(const _Safe_iterator<_Iterator, _Sequence>& __it) + { + return + __it.base() == __it._M_get_sequence()->_M_base().before_begin(); + } - static bool - _S_Is_Beginnest(_BaseIt __it, const _Sequence* __seq) - { return _S_Is(__it, __seq); } + template + static bool + _S_Is_Beginnest(const _Safe_iterator<_Iterator, _Sequence>& __it) + { return _S_Is(__it); } }; #ifndef _GLIBCXX_DEBUG_PEDANTIC template struct _Insert_range_from_self_is_safe< std::__debug::forward_list<_Tp, _Alloc> > - { enum { __value = 1 }; }; + { enum { __value = 1 }; }; #endif } diff --git a/libstdc++-v3/include/debug/safe_iterator.h b/libstdc++-v3/include/debug/safe_iterator.h index 9e73bcfd..59ba602 100644 --- a/libstdc++-v3/include/debug/safe_iterator.h +++ b/libstdc++-v3/include/debug/safe_iterator.h @@ -44,16 +44,15 @@ namespace __gnu_debug template struct _BeforeBeginHelper { - typedef typename _Sequence::const_iterator _It; - typedef typename _It::iterator_type _BaseIt; - - static bool - _S_Is(_BaseIt, const _Sequence*) - { return false; } - - static bool - _S_Is_Beginnest(_BaseIt __it, const _Sequence* __seq) - { return __it == __seq->_M_base().begin(); } + template + static bool + _S_Is(const _Safe_iterator<_Iterator, _Sequence>&) + { return false; } + + template + static bool + _S_Is_Beginnest(const _Safe_iterator<_Iterator, _Sequence>& __it) + { return __it.base() == __it._M_get_sequence()->_M_base().begin(); } }; /** Iterators that derive from _Safe_iterator_base can be determined singular @@ -76,26 +75,26 @@ namespace __gnu_debug /** Determine the distance between two iterators with some known * precision. */ - template - inline std::pair::difference_type, + template + inline std::pair::difference_type, _Distance_precision> - __get_distance(const _Iterator1& __lhs, const _Iterator2& __rhs, + __get_distance(const _Iterator& __lhs, const _Iterator& __rhs, std::random_access_iterator_tag) { return std::make_pair(__rhs - __lhs, __dp_exact); } - template - inline std::pair::difference_type, + template + inline std::pair::difference_type, _Distance_precision> - __get_distance(const _Iterator1& __lhs, const _Iterator2& __rhs, + __get_distance(const _Iterator& __lhs, const _Iterator& __rhs, std::forward_iterator_tag) { return std::make_pair(__lhs == __rhs? 0 : 1, __dp_equality); } - template - inline std::pair::difference_type, + template + inline std::pair::difference_type, _Distance_precision> - __get_distance(const _Iterator1& __lhs, const _Iterator2& __rhs) + __get_distance(const _Iterator& __lhs, const _Iterator& __rhs) { - typedef typename std::iterator_traits<_Iterator1>::iterator_category + typedef typename std::iterator_traits<_Iterator>::iterator_category _Category; return __get_distance(__lhs, __rhs, _Category()); } @@ -115,6 +114,7 @@ namespace __gnu_debug class _Safe_iterator : public _Safe_iterator_base { typedef _Safe_iterator _Self; + typedef typename _Sequence::const_iterator _Const_iterator; /// The underlying iterator _Iterator _M_current; @@ -122,10 +122,7 @@ namespace __gnu_debug /// Determine if this is a constant iterator. bool _M_constant() const - { - typedef typename _Sequence::const_iterator const_iterator; - return std::__are_same::__value; - } + { return std::__are_same<_Const_iterator, _Safe_iterator>::__value; } typedef std::iterator_traits<_Iterator> _Traits; @@ -445,37 +442,39 @@ namespace __gnu_debug _M_can_advance(const difference_type& __n) const; // Is the iterator range [*this, __rhs) valid? - template - bool - _M_valid_range(const _Safe_iterator<_Other, _Sequence>& __rhs) const; + bool + _M_valid_range(const _Safe_iterator& __rhs) const; // The sequence this iterator references. - const _Sequence* + typename + __gnu_cxx::__conditional_type::__value, + const _Sequence*, + _Sequence*>::__type _M_get_sequence() const - { return static_cast(_M_sequence); } + { return static_cast<_Sequence*>(_M_sequence); } /// Is this iterator equal to the sequence's begin() iterator? - bool _M_is_begin() const + bool + _M_is_begin() const { return base() == _M_get_sequence()->_M_base().begin(); } /// Is this iterator equal to the sequence's end() iterator? - bool _M_is_end() const + bool + _M_is_end() const { return base() == _M_get_sequence()->_M_base().end(); } /// Is this iterator equal to the sequence's before_begin() iterator if /// any? - bool _M_is_before_begin() const - { - return _BeforeBeginHelper<_Sequence>::_S_Is(base(), _M_get_sequence()); - } + bool + _M_is_before_begin() const + { return _BeforeBeginHelper<_Sequence>::_S_Is(*this); } /// Is this iterator equal to the sequence's before_begin() iterator if /// any or begin() otherwise? - bool _M_is_beginnest() const - { - return _BeforeBeginHelper<_Sequence>::_S_Is_Beginnest(base(), - _M_get_sequence()); - } + bool + _M_is_beginnest() const + { return _BeforeBeginHelper<_Sequence>::_S_Is_Beginnest(*this); } }; template diff --git a/libstdc++-v3/include/debug/safe_iterator.tcc b/libstdc++-v3/include/debug/safe_iterator.tcc index daa9c6b..7550a1d 100644 --- a/libstdc++-v3/include/debug/safe_iterator.tcc +++ b/libstdc++-v3/include/debug/safe_iterator.tcc @@ -36,27 +36,22 @@ namespace __gnu_debug _Safe_iterator<_Iterator, _Sequence>:: _M_can_advance(const difference_type& __n) const { - typedef typename _Sequence::const_iterator const_debug_iterator; - typedef typename const_debug_iterator::iterator_type const_iterator; - if (this->_M_singular()) return false; if (__n == 0) return true; if (__n < 0) { - const_iterator __begin = _M_get_sequence()->_M_base().begin(); std::pair __dist = - __get_distance(__begin, base()); + __get_distance(_M_get_sequence()->_M_base().begin(), base()); bool __ok = ((__dist.second == __dp_exact && __dist.first >= -__n) || (__dist.second != __dp_exact && __dist.first > 0)); return __ok; } else { - const_iterator __end = _M_get_sequence()->_M_base().end(); std::pair __dist = - __get_distance(base(), __end); + __get_distance(base(), _M_get_sequence()->_M_base().end()); bool __ok = ((__dist.second == __dp_exact && __dist.first >= __n) || (__dist.second != __dp_exact && __dist.first > 0)); return __ok; @@ -64,42 +59,41 @@ namespace __gnu_debug } template - template - bool - _Safe_iterator<_Iterator, _Sequence>:: - _M_valid_range(const _Safe_iterator<_Other, _Sequence>& __rhs) const - { - if (!_M_can_compare(__rhs)) - return false; - - /* Determine if we can order the iterators without the help of - the container */ - std::pair __dist = - __get_distance(base(), __rhs.base()); - switch (__dist.second) { - case __dp_equality: - if (__dist.first == 0) - return true; - break; - - case __dp_sign: - case __dp_exact: - return __dist.first >= 0; - } + bool + _Safe_iterator<_Iterator, _Sequence>:: + _M_valid_range(const _Safe_iterator& __rhs) const + { + if (!_M_can_compare(__rhs)) + return false; - /* We can only test for equality, but check if one of the - iterators is at an extreme. */ - /* Optim for classic [begin, it) or [it, end) ranges, limit checks - * when code is valid. Note, for the special case of forward_list, - * before_begin replaces the role of begin. */ - if (_M_is_beginnest() || __rhs._M_is_end()) + /* Determine if we can order the iterators without the help of + the container */ + std::pair __dist = + __get_distance(base(), __rhs.base()); + switch (__dist.second) { + case __dp_equality: + if (__dist.first == 0) return true; - if (_M_is_end() || __rhs._M_is_beginnest()) - return false; + break; - // Assume that this is a valid range; we can't check anything else - return true; + case __dp_sign: + case __dp_exact: + return __dist.first >= 0; } + + /* We can only test for equality, but check if one of the + iterators is at an extreme. */ + /* Optim for classic [begin, it) or [it, end) ranges, limit checks + * when code is valid. Note, for the special case of forward_list, + * before_begin replaces the role of begin. */ + if (_M_is_beginnest() || __rhs._M_is_end()) + return true; + if (_M_is_end() || __rhs._M_is_beginnest()) + return false; + + // Assume that this is a valid range; we can't check anything else + return true; + } } // namespace __gnu_debug #endif diff --git a/libstdc++-v3/include/debug/safe_local_iterator.h b/libstdc++-v3/include/debug/safe_local_iterator.h index 82975b7..6724798 100644 --- a/libstdc++-v3/include/debug/safe_local_iterator.h +++ b/libstdc++-v3/include/debug/safe_local_iterator.h @@ -52,6 +52,7 @@ namespace __gnu_debug class _Safe_local_iterator : public _Safe_local_iterator_base { typedef _Safe_local_iterator _Self; + typedef typename _Sequence::const_local_iterator _Const_local_iterator; typedef typename _Sequence::size_type size_type; /// The underlying iterator @@ -64,8 +65,8 @@ namespace __gnu_debug bool _M_constant() const { - typedef typename _Sequence::const_local_iterator const_iterator; - return std::__are_same::__value; + return std::__are_same<_Const_local_iterator, + _Safe_local_iterator>::__value; } typedef std::iterator_traits<_Iterator> _Traits; @@ -253,15 +254,17 @@ namespace __gnu_debug { return !this->_M_singular() && !_M_is_end(); } // Is the iterator range [*this, __rhs) valid? - template - bool - _M_valid_range(const _Safe_local_iterator<_Other, - _Sequence>& __rhs) const; + bool + _M_valid_range(const _Safe_local_iterator& __rhs) const; // The sequence this iterator references. - const _Sequence* + typename + __gnu_cxx::__conditional_type::__value, + const _Sequence*, + _Sequence*>::__type _M_get_sequence() const - { return static_cast(_M_sequence); } + { return static_cast<_Sequence*>(_M_sequence); } /// Is this iterator equal to the sequence's begin() iterator? bool _M_is_begin() const diff --git a/libstdc++-v3/include/debug/safe_local_iterator.tcc b/libstdc++-v3/include/debug/safe_local_iterator.tcc index fac971e..6633bdb 100644 --- a/libstdc++-v3/include/debug/safe_local_iterator.tcc +++ b/libstdc++-v3/include/debug/safe_local_iterator.tcc @@ -32,21 +32,20 @@ namespace __gnu_debug { template - template - bool - _Safe_local_iterator<_Iterator, _Sequence>:: - _M_valid_range(const _Safe_local_iterator<_Other, _Sequence>& __rhs) const - { - if (!_M_can_compare(__rhs)) - return false; - if (_M_bucket != __rhs._M_bucket) - return false; + bool + _Safe_local_iterator<_Iterator, _Sequence>:: + _M_valid_range(const _Safe_local_iterator& __rhs) const + { + if (!_M_can_compare(__rhs)) + return false; + if (_M_bucket != __rhs._M_bucket) + return false; - /* Determine if we can order the iterators without the help of - the container */ - std::pair __dist = - __get_distance(base(), __rhs.base()); - switch (__dist.second) + /* Determine if we can order the iterators without the help of + the container */ + std::pair __dist = + __get_distance(base(), __rhs.base()); + switch (__dist.second) { case __dp_equality: if (__dist.first == 0) @@ -58,18 +57,18 @@ namespace __gnu_debug return __dist.first >= 0; } - /* We can only test for equality, but check if one of the - iterators is at an extreme. */ - /* Optim for classic [begin, it) or [it, end) ranges, limit checks - * when code is valid. */ - if (_M_is_begin() || __rhs._M_is_end()) - return true; - if (_M_is_end() || __rhs._M_is_begin()) - return false; - - // Assume that this is a valid range; we can't check anything else + /* We can only test for equality, but check if one of the + iterators is at an extreme. */ + /* Optim for classic [begin, it) or [it, end) ranges, limit checks + * when code is valid. */ + if (_M_is_begin() || __rhs._M_is_end()) return true; - } + if (_M_is_end() || __rhs._M_is_begin()) + return false; + + // Assume that this is a valid range; we can't check anything else + return true; + } } // namespace __gnu_debug #endif -- 2.7.4