OSDN Git Service

2005-10-05 Paolo Carlini <pcarlini@suse.de>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 5 Oct 2005 15:49:39 +0000 (15:49 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 5 Oct 2005 15:49:39 +0000 (15:49 +0000)
PR libstdc++/11729 (DR 280, [Ready])
* include/bits/stl_iterator.h: Add reverse_iterator global
functions with two template parameters (operator==, !=, <,
>, <=, >=, -).
* testsuite/24_iterators/reverse_iterator/11729.cc: New.
* docs/html/ext/howto.html: Add an entry for issue 280.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@105000 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/docs/html/ext/howto.html
libstdc++-v3/include/bits/stl_iterator.h
libstdc++-v3/testsuite/24_iterators/reverse_iterator/11729.cc [new file with mode: 0644]

index 1d0fc12..940f6ab 100644 (file)
@@ -1,3 +1,12 @@
+2005-10-05  Paolo Carlini  <pcarlini@suse.de>
+
+       PR libstdc++/11729 (DR 280, [Ready])
+       * include/bits/stl_iterator.h: Add reverse_iterator global
+       functions with two template parameters (operator==, !=, <,
+       >, <=, >=, -).
+       * testsuite/24_iterators/reverse_iterator/11729.cc: New.
+       * docs/html/ext/howto.html: Add an entry for issue 280.
+
 2005-10-03  Paolo Carlini  <pcarlini@suse.de>
 
        * include/tr1/hashtable
index 8516196..b22b56e 100644 (file)
     <dd>Similar to 118.
     </dd>
 
+    <dt><a href="lwg-active.html#280">280</a>:
+        <em>Comparison of reverse_iterator to const reverse_iterator</em>
+    </dt>
+    <dd>Add global functions with two template parameters.
+        (NB: not added for now a templated assignment operator) 
+    </dd>
+
     <dt><a href="lwg-defects.html#292">292</a>:
         <em>Effects of a.copyfmt (a)</em>
     </dt>
index 5b8cf65..4c4630a 100644 (file)
@@ -205,7 +205,8 @@ namespace std
        *
        *  @doctodo
       */
-      reverse_iterator operator--(int)
+      reverse_iterator
+      operator--(int)
       {
        reverse_iterator __tmp = *this;
        ++current;
@@ -301,7 +302,7 @@ namespace std
   template<typename _Iterator>
     inline bool
     operator<=(const reverse_iterator<_Iterator>& __x,
-               const reverse_iterator<_Iterator>& __y)
+              const reverse_iterator<_Iterator>& __y)
     { return !(__y < __x); }
 
   template<typename _Iterator>
@@ -321,6 +322,50 @@ namespace std
     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
              const reverse_iterator<_Iterator>& __x)
     { return reverse_iterator<_Iterator>(__x.base() - __n); }
+
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // DR 280. Comparison of reverse_iterator to const reverse_iterator.
+  template<typename _IteratorL, typename _IteratorR>
+    inline bool
+    operator==(const reverse_iterator<_IteratorL>& __x,
+              const reverse_iterator<_IteratorR>& __y)
+    { return __x.base() == __y.base(); }
+
+  template<typename _IteratorL, typename _IteratorR>
+    inline bool
+    operator<(const reverse_iterator<_IteratorL>& __x,
+             const reverse_iterator<_IteratorR>& __y)
+    { return __y.base() < __x.base(); }
+
+  template<typename _IteratorL, typename _IteratorR>
+    inline bool
+    operator!=(const reverse_iterator<_IteratorL>& __x,
+              const reverse_iterator<_IteratorR>& __y)
+    { return !(__x == __y); }
+
+  template<typename _IteratorL, typename _IteratorR>
+    inline bool
+    operator>(const reverse_iterator<_IteratorL>& __x,
+             const reverse_iterator<_IteratorR>& __y)
+    { return __y < __x; }
+
+  template<typename _IteratorL, typename _IteratorR>
+    inline bool
+    operator<=(const reverse_iterator<_IteratorL>& __x,
+              const reverse_iterator<_IteratorR>& __y)
+    { return !(__y < __x); }
+
+  template<typename _IteratorL, typename _IteratorR>
+    inline bool
+    operator>=(const reverse_iterator<_IteratorL>& __x,
+              const reverse_iterator<_IteratorR>& __y)
+    { return !(__x < __y); }
+
+  template<typename _IteratorL, typename _IteratorR>
+    inline typename reverse_iterator<_IteratorL>::difference_type
+    operator-(const reverse_iterator<_IteratorL>& __x,
+             const reverse_iterator<_IteratorR>& __y)
+    { return __y.base() - __x.base(); }
   //@}
 
   // 24.4.2.2.1 back_insert_iterator
diff --git a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/11729.cc b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/11729.cc
new file mode 100644 (file)
index 0000000..f79be3e
--- /dev/null
@@ -0,0 +1,73 @@
+// 2005-10-04  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2005 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 24.4.1.2 Reverse iterators
+
+#include <vector>
+#include <testsuite_hooks.h>
+
+// libstdc++/11729
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  typedef std::vector<int> Vec;
+  typedef Vec::reverse_iterator reverse_iterator;
+  typedef Vec::const_reverse_iterator const_reverse_iterator;
+  
+  Vec v(2);
+
+  reverse_iterator rbeg = v.rbegin();               
+  reverse_iterator rend = v.rend();
+  const_reverse_iterator constrbeg(rbeg);
+  const_reverse_iterator constrend(rend);
+
+  VERIFY( rbeg == constrbeg );
+  VERIFY( constrend == rend );
+
+  VERIFY( rbeg != constrend );
+  VERIFY( constrbeg != rend );
+
+  VERIFY( rbeg < constrend );
+  VERIFY( constrbeg < rend );
+
+  VERIFY( rend > constrbeg );
+  VERIFY( constrend > rbeg );
+
+  VERIFY( rend >= constrend );
+  VERIFY( constrbeg >= rbeg );
+
+  VERIFY( rbeg <= constrbeg );
+  VERIFY( constrend <= rend );
+
+  VERIFY( rbeg - constrbeg == 0 );
+  VERIFY( constrend - rend == 0 );
+
+  VERIFY( rend - constrbeg > 0 );
+  VERIFY( constrend - rbeg > 0 );
+
+  VERIFY( (constrbeg = rend) == rend );
+}
+
+int main() 
+{ 
+  test01();
+  return 0;
+}