Commit 9fc0e24b by François Dumont

safe_iterator.h (_BeforeBeginHelper<>::_S_Is): Take only a const safe iterator reference.

2013-11-08  François Dumont  <fdumont@gcc.gnu.org>

	* 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<std::__debug::forward_list<>>): Adapt.

From-SVN: r204598
parent d53b3432
2013-11-08 François Dumont <fdumont@gcc.gnu.org>
* 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<std::__debug::forward_list<>>): Adapt.
2013-11-08 Jonathan Wakely <jwakely.gcc@gmail.com> 2013-11-08 Jonathan Wakely <jwakely.gcc@gmail.com>
* include/bits/regex_automaton.h (__detail::_State): Split * include/bits/regex_automaton.h (__detail::_State): Split
......
...@@ -785,16 +785,19 @@ namespace __gnu_debug ...@@ -785,16 +785,19 @@ namespace __gnu_debug
struct _BeforeBeginHelper<std::__debug::forward_list<_Tp, _Alloc> > struct _BeforeBeginHelper<std::__debug::forward_list<_Tp, _Alloc> >
{ {
typedef std::__debug::forward_list<_Tp, _Alloc> _Sequence; typedef std::__debug::forward_list<_Tp, _Alloc> _Sequence;
typedef typename _Sequence::const_iterator _It;
typedef typename _It::iterator_type _BaseIt;
template<typename _Iterator>
static bool static bool
_S_Is(_BaseIt __it, const _Sequence* __seq) _S_Is(const _Safe_iterator<_Iterator, _Sequence>& __it)
{ return __it == __seq->_M_base().cbefore_begin(); } {
return
__it.base() == __it._M_get_sequence()->_M_base().before_begin();
}
template<typename _Iterator>
static bool static bool
_S_Is_Beginnest(_BaseIt __it, const _Sequence* __seq) _S_Is_Beginnest(const _Safe_iterator<_Iterator, _Sequence>& __it)
{ return _S_Is(__it, __seq); } { return _S_Is(__it); }
}; };
#ifndef _GLIBCXX_DEBUG_PEDANTIC #ifndef _GLIBCXX_DEBUG_PEDANTIC
......
...@@ -44,16 +44,15 @@ namespace __gnu_debug ...@@ -44,16 +44,15 @@ namespace __gnu_debug
template <typename _Sequence> template <typename _Sequence>
struct _BeforeBeginHelper struct _BeforeBeginHelper
{ {
typedef typename _Sequence::const_iterator _It; template<typename _Iterator>
typedef typename _It::iterator_type _BaseIt;
static bool static bool
_S_Is(_BaseIt, const _Sequence*) _S_Is(const _Safe_iterator<_Iterator, _Sequence>&)
{ return false; } { return false; }
template<typename _Iterator>
static bool static bool
_S_Is_Beginnest(_BaseIt __it, const _Sequence* __seq) _S_Is_Beginnest(const _Safe_iterator<_Iterator, _Sequence>& __it)
{ return __it == __seq->_M_base().begin(); } { return __it.base() == __it._M_get_sequence()->_M_base().begin(); }
}; };
/** Iterators that derive from _Safe_iterator_base can be determined singular /** Iterators that derive from _Safe_iterator_base can be determined singular
...@@ -76,26 +75,26 @@ namespace __gnu_debug ...@@ -76,26 +75,26 @@ namespace __gnu_debug
/** Determine the distance between two iterators with some known /** Determine the distance between two iterators with some known
* precision. * precision.
*/ */
template<typename _Iterator1, typename _Iterator2> template<typename _Iterator>
inline std::pair<typename std::iterator_traits<_Iterator1>::difference_type, inline std::pair<typename std::iterator_traits<_Iterator>::difference_type,
_Distance_precision> _Distance_precision>
__get_distance(const _Iterator1& __lhs, const _Iterator2& __rhs, __get_distance(const _Iterator& __lhs, const _Iterator& __rhs,
std::random_access_iterator_tag) std::random_access_iterator_tag)
{ return std::make_pair(__rhs - __lhs, __dp_exact); } { return std::make_pair(__rhs - __lhs, __dp_exact); }
template<typename _Iterator1, typename _Iterator2> template<typename _Iterator>
inline std::pair<typename std::iterator_traits<_Iterator1>::difference_type, inline std::pair<typename std::iterator_traits<_Iterator>::difference_type,
_Distance_precision> _Distance_precision>
__get_distance(const _Iterator1& __lhs, const _Iterator2& __rhs, __get_distance(const _Iterator& __lhs, const _Iterator& __rhs,
std::forward_iterator_tag) std::forward_iterator_tag)
{ return std::make_pair(__lhs == __rhs? 0 : 1, __dp_equality); } { return std::make_pair(__lhs == __rhs? 0 : 1, __dp_equality); }
template<typename _Iterator1, typename _Iterator2> template<typename _Iterator>
inline std::pair<typename std::iterator_traits<_Iterator1>::difference_type, inline std::pair<typename std::iterator_traits<_Iterator>::difference_type,
_Distance_precision> _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; _Category;
return __get_distance(__lhs, __rhs, _Category()); return __get_distance(__lhs, __rhs, _Category());
} }
...@@ -115,6 +114,7 @@ namespace __gnu_debug ...@@ -115,6 +114,7 @@ namespace __gnu_debug
class _Safe_iterator : public _Safe_iterator_base class _Safe_iterator : public _Safe_iterator_base
{ {
typedef _Safe_iterator _Self; typedef _Safe_iterator _Self;
typedef typename _Sequence::const_iterator _Const_iterator;
/// The underlying iterator /// The underlying iterator
_Iterator _M_current; _Iterator _M_current;
...@@ -122,10 +122,7 @@ namespace __gnu_debug ...@@ -122,10 +122,7 @@ namespace __gnu_debug
/// Determine if this is a constant iterator. /// Determine if this is a constant iterator.
bool bool
_M_constant() const _M_constant() const
{ { return std::__are_same<_Const_iterator, _Safe_iterator>::__value; }
typedef typename _Sequence::const_iterator const_iterator;
return std::__are_same<const_iterator, _Safe_iterator>::__value;
}
typedef std::iterator_traits<_Iterator> _Traits; typedef std::iterator_traits<_Iterator> _Traits;
...@@ -445,37 +442,39 @@ namespace __gnu_debug ...@@ -445,37 +442,39 @@ namespace __gnu_debug
_M_can_advance(const difference_type& __n) const; _M_can_advance(const difference_type& __n) const;
// Is the iterator range [*this, __rhs) valid? // Is the iterator range [*this, __rhs) valid?
template<typename _Other>
bool bool
_M_valid_range(const _Safe_iterator<_Other, _Sequence>& __rhs) const; _M_valid_range(const _Safe_iterator& __rhs) const;
// The sequence this iterator references. // The sequence this iterator references.
const _Sequence* typename
__gnu_cxx::__conditional_type<std::__are_same<_Const_iterator,
_Safe_iterator>::__value,
const _Sequence*,
_Sequence*>::__type
_M_get_sequence() const _M_get_sequence() const
{ return static_cast<const _Sequence*>(_M_sequence); } { return static_cast<_Sequence*>(_M_sequence); }
/// Is this iterator equal to the sequence's begin() iterator? /// 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(); } { return base() == _M_get_sequence()->_M_base().begin(); }
/// Is this iterator equal to the sequence's end() iterator? /// 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(); } { return base() == _M_get_sequence()->_M_base().end(); }
/// Is this iterator equal to the sequence's before_begin() iterator if /// Is this iterator equal to the sequence's before_begin() iterator if
/// any? /// any?
bool _M_is_before_begin() const bool
{ _M_is_before_begin() const
return _BeforeBeginHelper<_Sequence>::_S_Is(base(), _M_get_sequence()); { return _BeforeBeginHelper<_Sequence>::_S_Is(*this); }
}
/// Is this iterator equal to the sequence's before_begin() iterator if /// Is this iterator equal to the sequence's before_begin() iterator if
/// any or begin() otherwise? /// any or begin() otherwise?
bool _M_is_beginnest() const bool
{ _M_is_beginnest() const
return _BeforeBeginHelper<_Sequence>::_S_Is_Beginnest(base(), { return _BeforeBeginHelper<_Sequence>::_S_Is_Beginnest(*this); }
_M_get_sequence());
}
}; };
template<typename _IteratorL, typename _IteratorR, typename _Sequence> template<typename _IteratorL, typename _IteratorR, typename _Sequence>
......
...@@ -36,27 +36,22 @@ namespace __gnu_debug ...@@ -36,27 +36,22 @@ namespace __gnu_debug
_Safe_iterator<_Iterator, _Sequence>:: _Safe_iterator<_Iterator, _Sequence>::
_M_can_advance(const difference_type& __n) const _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()) if (this->_M_singular())
return false; return false;
if (__n == 0) if (__n == 0)
return true; return true;
if (__n < 0) if (__n < 0)
{ {
const_iterator __begin = _M_get_sequence()->_M_base().begin();
std::pair<difference_type, _Distance_precision> __dist = std::pair<difference_type, _Distance_precision> __dist =
__get_distance(__begin, base()); __get_distance(_M_get_sequence()->_M_base().begin(), base());
bool __ok = ((__dist.second == __dp_exact && __dist.first >= -__n) bool __ok = ((__dist.second == __dp_exact && __dist.first >= -__n)
|| (__dist.second != __dp_exact && __dist.first > 0)); || (__dist.second != __dp_exact && __dist.first > 0));
return __ok; return __ok;
} }
else else
{ {
const_iterator __end = _M_get_sequence()->_M_base().end();
std::pair<difference_type, _Distance_precision> __dist = std::pair<difference_type, _Distance_precision> __dist =
__get_distance(base(), __end); __get_distance(base(), _M_get_sequence()->_M_base().end());
bool __ok = ((__dist.second == __dp_exact && __dist.first >= __n) bool __ok = ((__dist.second == __dp_exact && __dist.first >= __n)
|| (__dist.second != __dp_exact && __dist.first > 0)); || (__dist.second != __dp_exact && __dist.first > 0));
return __ok; return __ok;
...@@ -64,10 +59,9 @@ namespace __gnu_debug ...@@ -64,10 +59,9 @@ namespace __gnu_debug
} }
template<typename _Iterator, typename _Sequence> template<typename _Iterator, typename _Sequence>
template<typename _Other>
bool bool
_Safe_iterator<_Iterator, _Sequence>:: _Safe_iterator<_Iterator, _Sequence>::
_M_valid_range(const _Safe_iterator<_Other, _Sequence>& __rhs) const _M_valid_range(const _Safe_iterator& __rhs) const
{ {
if (!_M_can_compare(__rhs)) if (!_M_can_compare(__rhs))
return false; return false;
......
...@@ -52,6 +52,7 @@ namespace __gnu_debug ...@@ -52,6 +52,7 @@ namespace __gnu_debug
class _Safe_local_iterator : public _Safe_local_iterator_base class _Safe_local_iterator : public _Safe_local_iterator_base
{ {
typedef _Safe_local_iterator _Self; typedef _Safe_local_iterator _Self;
typedef typename _Sequence::const_local_iterator _Const_local_iterator;
typedef typename _Sequence::size_type size_type; typedef typename _Sequence::size_type size_type;
/// The underlying iterator /// The underlying iterator
...@@ -64,8 +65,8 @@ namespace __gnu_debug ...@@ -64,8 +65,8 @@ namespace __gnu_debug
bool bool
_M_constant() const _M_constant() const
{ {
typedef typename _Sequence::const_local_iterator const_iterator; return std::__are_same<_Const_local_iterator,
return std::__are_same<const_iterator, _Safe_local_iterator>::__value; _Safe_local_iterator>::__value;
} }
typedef std::iterator_traits<_Iterator> _Traits; typedef std::iterator_traits<_Iterator> _Traits;
...@@ -253,15 +254,17 @@ namespace __gnu_debug ...@@ -253,15 +254,17 @@ namespace __gnu_debug
{ return !this->_M_singular() && !_M_is_end(); } { return !this->_M_singular() && !_M_is_end(); }
// Is the iterator range [*this, __rhs) valid? // Is the iterator range [*this, __rhs) valid?
template<typename _Other>
bool bool
_M_valid_range(const _Safe_local_iterator<_Other, _M_valid_range(const _Safe_local_iterator& __rhs) const;
_Sequence>& __rhs) const;
// The sequence this iterator references. // The sequence this iterator references.
const _Sequence* typename
__gnu_cxx::__conditional_type<std::__are_same<_Const_local_iterator,
_Safe_local_iterator>::__value,
const _Sequence*,
_Sequence*>::__type
_M_get_sequence() const _M_get_sequence() const
{ return static_cast<const _Sequence*>(_M_sequence); } { return static_cast<_Sequence*>(_M_sequence); }
/// Is this iterator equal to the sequence's begin() iterator? /// Is this iterator equal to the sequence's begin() iterator?
bool _M_is_begin() const bool _M_is_begin() const
......
...@@ -32,10 +32,9 @@ ...@@ -32,10 +32,9 @@
namespace __gnu_debug namespace __gnu_debug
{ {
template<typename _Iterator, typename _Sequence> template<typename _Iterator, typename _Sequence>
template<typename _Other>
bool bool
_Safe_local_iterator<_Iterator, _Sequence>:: _Safe_local_iterator<_Iterator, _Sequence>::
_M_valid_range(const _Safe_local_iterator<_Other, _Sequence>& __rhs) const _M_valid_range(const _Safe_local_iterator& __rhs) const
{ {
if (!_M_can_compare(__rhs)) if (!_M_can_compare(__rhs))
return false; return false;
......
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