From 276e31ec6eadb5318f9a826f36642a324668d796 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sun, 7 Jul 2002 12:15:06 +0200 Subject: [PATCH] re PR libstdc++/7186 (DR179 for std::deque::iterator and const_iterator) 2002-07-07 Paolo Carlini 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 --- libstdc++-v3/ChangeLog | 8 +++++++ libstdc++-v3/include/bits/stl_deque.h | 21 +++++++++++++----- .../23_containers/deque_operators.cc | 22 +++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 90d0eb7864d..874d673a65c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2002-07-07 Paolo Carlini + + 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 Jack Reeves diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index 1eedc6a1abf..cbf8ad34577 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -132,11 +132,6 @@ template 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 +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 inline _Deque_iterator<_Tp, _Ref, _Ptr> operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x) diff --git a/libstdc++-v3/testsuite/23_containers/deque_operators.cc b/libstdc++-v3/testsuite/23_containers/deque_operators.cc index 9585514c8de..5463b47f1cb 100644 --- a/libstdc++-v3/testsuite/23_containers/deque_operators.cc +++ b/libstdc++-v3/testsuite/23_containers/deque_operators.cc @@ -56,8 +56,30 @@ void test01() VERIFY( constend <= end ); } +// libstdc++/7186 +void test02() +{ + bool test = true; + + std::deque d(2); + typedef std::deque::iterator iter; + typedef std::deque::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; } -- 2.30.2