re PR libstdc++/7186 (DR179 for std::deque::iterator and const_iterator)

2002-07-07  Paolo Carlini  <pcarlini@unitus.it>

	PR libstdc++/7186
	* include/bits/stl_deque.h (_Deque_iterator::operator-):
	Make non-member, as already happens for the comparison
	operators in accord with DR179 (Ready).
	* testsuite/23_containers/deque_operators.cc: Add test02.

From-SVN: r55301
This commit is contained in:
Paolo Carlini 2002-07-07 12:15:06 +02:00 committed by Paolo Carlini
parent 12f2f485a3
commit 276e31ec6e
3 changed files with 46 additions and 5 deletions

View File

@ -1,3 +1,11 @@
2002-07-07 Paolo Carlini <pcarlini@unitus.it>
PR libstdc++/7186
* include/bits/stl_deque.h (_Deque_iterator::operator-):
Make non-member, as already happens for the comparison
operators in accord with DR179 (Ready).
* testsuite/23_containers/deque_operators.cc: Add test02.
2002-07-04 Benjamin Kosnik <bkoz@redhat.com>
Jack Reeves <jackw_reeves@hotmail.com>

View File

@ -132,11 +132,6 @@ template <typename _Tp, typename _Ref, typename _Ptr>
reference operator*() const { return *_M_cur; }
pointer operator->() const { return _M_cur; }
difference_type operator-(const _Self& __x) const {
return difference_type(_S_buffer_size()) * (_M_node - __x._M_node - 1) +
(_M_cur - _M_first) + (__x._M_last - __x._M_cur);
}
_Self& operator++() {
++_M_cur;
if (_M_cur == _M_last) {
@ -318,6 +313,22 @@ operator>=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
return !(__x < __y);
}
// _GLIBCPP_RESOLVE_LIB_DEFECTS
// According to the resolution of DR179 not only the various comparison
// operators but also operator- must accept mixed iterator/const_iterator
// parameters.
template <typename _Tp, typename _RefL, typename _PtrL,
typename _RefR, typename _PtrR>
inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
{
return _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
(_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size()) *
(__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first) +
(__y._M_last - __y._M_cur);
}
template <typename _Tp, typename _Ref, typename _Ptr>
inline _Deque_iterator<_Tp, _Ref, _Ptr>
operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)

View File

@ -56,8 +56,30 @@ void test01()
VERIFY( constend <= end );
}
// libstdc++/7186
void test02()
{
bool test = true;
std::deque<int> d(2);
typedef std::deque<int>::iterator iter;
typedef std::deque<int>::const_iterator constiter;
iter beg = d.begin();
iter end = d.end();
constiter constbeg = d.begin();
constiter constend = d.end();
VERIFY( beg - constbeg == 0 );
VERIFY( constend - end == 0 );
VERIFY( end - constbeg > 0 );
VERIFY( constend - beg > 0 );
}
int main()
{
test01();
test02();
return 0;
}