diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 1d0fc12d4b4e5f2fe4fc358a3d9fdd1f6d141e0f..940f6ab45dce0a36c85287b58724a0a7efb30e91 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -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 diff --git a/libstdc++-v3/docs/html/ext/howto.html b/libstdc++-v3/docs/html/ext/howto.html index 85161964e5f31f5c14e885a2f1c6fc80e0dd38ca..b22b56e062287b58d054ec4ae88a45b00ef3adfa 100644 --- a/libstdc++-v3/docs/html/ext/howto.html +++ b/libstdc++-v3/docs/html/ext/howto.html @@ -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> diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 5b8cf65e6d85fef4e590964e4d27d10a3c5189a1..4c4630a06896f849d8d123e221568f7d856789e1 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -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 index 0000000000000000000000000000000000000000..f79be3ebb4c61580abc0ace06fb353018458a581 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/11729.cc @@ -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; +}