re PR libstdc++/7186 (DR179 for std::deque::iterator and const_iterator)
authorPaolo Carlini <pcarlini@unitus.it>
Sun, 7 Jul 2002 10:15:06 +0000 (12:15 +0200)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sun, 7 Jul 2002 10:15:06 +0000 (10:15 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stl_deque.h
libstdc++-v3/testsuite/23_containers/deque_operators.cc

index 90d0eb7864da120ec798f2b0ac357550074b5799..874d673a65cf2a6063081af11b56d4f09a4c4e1f 100644 (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>
 
index 1eedc6a1abf59c40637578a00557df2245fcdaa0..cbf8ad345779af2c50981752acf26446a5290b16 100644 (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)
index 9585514c8de9e7858484f1f808ae0c5248b9b1ef..5463b47f1cb119c9a80d4e90f8a866594c180144 100644 (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;
 }