This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] libstdc++/11729 (DR 280)
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 04 Oct 2005 20:25:46 +0200
- Subject: [Patch] libstdc++/11729 (DR 280)
Hi,
in Lillehammer this issue became [Ready] and I believe we can safely
implement the resolution and close our *long* standing PR: I'm just
adding overloads with two template parameters instead of "upgrading"
with a second parameter the existing ones: the safest solution from the
point of view of binary compatibility (as also indicated by Steve Cleary
in the DR). This is also completely consistent with our iterator classes.
Honestly, I don't see a real need for also adding a templated assignment
operator (as per point A of the proposed resolution) and I would punt
for now on that - we can always add it later, in case - unless someone
can see a compelling reason for doing that now, feedback very appreciated!
Tested x86-linux.
Paolo.
///////////////
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.
Index: docs/html/ext/howto.html
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/docs/html/ext/howto.html,v
retrieving revision 1.57
diff -u -r1.57 howto.html
--- docs/html/ext/howto.html 29 Aug 2005 16:11:19 -0000 1.57
+++ docs/html/ext/howto.html 4 Oct 2005 17:41:18 -0000
@@ -453,6 +453,13 @@
<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: include/bits/stl_iterator.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_iterator.h,v
retrieving revision 1.29
diff -u -r1.29 stl_iterator.h
--- include/bits/stl_iterator.h 12 Sep 2005 09:42:29 -0000 1.29
+++ include/bits/stl_iterator.h 4 Oct 2005 17:41:18 -0000
@@ -205,7 +205,8 @@
*
* @doctodo
*/
- reverse_iterator operator--(int)
+ reverse_iterator
+ operator--(int)
{
reverse_iterator __tmp = *this;
++current;
@@ -301,7 +302,7 @@
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 @@
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
Index: testsuite/24_iterators/reverse_iterator/11729.cc
===================================================================
RCS file: testsuite/24_iterators/reverse_iterator/11729.cc
diff -N testsuite/24_iterators/reverse_iterator/11729.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/24_iterators/reverse_iterator/11729.cc 4 Oct 2005 17:41:19 -0000
@@ -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;
+}