diff options
author | Gabriel Dos Reis <gdr@gcc.gnu.org> | 2002-04-16 02:29:22 +0000 |
---|---|---|
committer | Gabriel Dos Reis <gdr@gcc.gnu.org> | 2002-04-16 02:29:22 +0000 |
commit | f1e888aea0089c38d73de22e2ad79e40d3e65da8 (patch) | |
tree | 7e3308a550a748ba7a7d885829b0372740682565 | |
parent | 902c431d489932297b7e2467790f324914820854 (diff) | |
download | gcc-f1e888aea0089c38d73de22e2ad79e40d3e65da8.zip gcc-f1e888aea0089c38d73de22e2ad79e40d3e65da8.tar.gz gcc-f1e888aea0089c38d73de22e2ad79e40d3e65da8.tar.bz2 |
[multiple changes]
2002-04-16 Paolo Carlini <pcarlini@unitus.it>
* testsuite/24_iterators/rel_ops.cc: New test.
2002-04-16 Gabriel Dos Reis <gdr@merlin.codesourcery.com>
* include/bits/type_traits.h (__normal_iterator): Declare in
__gnu_cxx. Adjust use at global namespace.
* include/bits/stl_iterator.h (__normal_iterator): Move
definition
into __gnu_cxx::. Add more operator overloads. Tidy existing
ones.
* include/bits/basic_string.h (basic_string): Adjust use of
__normal_iterator.
* include/bits/stl_vector.h (_Alloc>): Likewise.
* src/concept-inst.cc (__gnu_cxx): __normal_iterator<> is now
here.
* src/string-inst.cc (operator==): Instantiate in __gnu_cxx.
From-SVN: r52348
-rw-r--r-- | libstdc++-v3/ChangeLog | 15 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/basic_string.h | 5 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_iterator.h | 61 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_vector.h | 5 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/type_traits.h | 4 | ||||
-rw-r--r-- | libstdc++-v3/src/concept-inst.cc | 28 | ||||
-rw-r--r-- | libstdc++-v3/src/string-inst.cc | 8 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/24_iterators/rel_ops.cc | 45 |
8 files changed, 145 insertions, 26 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0bf364c..632ea3d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,18 @@ +2002-04-16 Paolo Carlini <pcarlini@unitus.it> + * testsuite/24_iterators/rel_ops.cc: New test. + +2002-04-16 Gabriel Dos Reis <gdr@merlin.codesourcery.com> + + * include/bits/type_traits.h (__normal_iterator): Declare in + __gnu_cxx. Adjust use at global namespace. + * include/bits/stl_iterator.h (__normal_iterator): Move definition + into __gnu_cxx::. Add more operator overloads. Tidy existing ones. + * include/bits/basic_string.h (basic_string): Adjust use of + __normal_iterator. + * include/bits/stl_vector.h (_Alloc>): Likewise. + * src/concept-inst.cc (__gnu_cxx): __normal_iterator<> is now here. + * src/string-inst.cc (operator==): Instantiate in __gnu_cxx. + 2002-04-15 Benjamin Kosnik <bkoz@redhat.com> PR libstdc++/4164 diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index ba539e7..ab2360f 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -99,8 +99,9 @@ namespace std typedef typename _Alloc::const_reference const_reference; typedef typename _Alloc::pointer pointer; typedef typename _Alloc::const_pointer const_pointer; - typedef __normal_iterator<pointer, basic_string> iterator; - typedef __normal_iterator<const_pointer, basic_string> const_iterator; + typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator; + typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string> + const_iterator; typedef reverse_iterator<const_iterator> const_reverse_iterator; typedef reverse_iterator<iterator> reverse_iterator; diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index b42181f..d8a6d8c 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -548,7 +548,10 @@ namespace std return insert_iterator<_Container>(__x, typename _Container::iterator(__i)); } - +} // namespace std + +namespace __gnu_cxx +{ // This iterator adapter is 'normal' in the sense that it does not // change the semantics of any of the operators of its iterator // parameter. Its primary purpose is to convert an iterator that is @@ -556,6 +559,8 @@ namespace std // The _Container parameter exists solely so that different containers // using this template can instantiate different types, even if the // _Iterator parameter is the same. + using std::iterator_traits; + using std::iterator; template<typename _Iterator, typename _Container> class __normal_iterator : public iterator<typename iterator_traits<_Iterator>::iterator_category, @@ -632,6 +637,14 @@ namespace std base() const { return _M_current; } }; + // Note: In what follows, the left- and right-hand-side iterators are + // allowed to vary in types (conceptually in cv-qualification) so that + // comparaison between cv-qualified and non-cv-qualified iterators be + // valid. However, the greedy and unfriendly operators in std::rel_ops + // will make overload resolution ambiguous (when in scope) if we don't + // provide overloads whose operands are of the same type. Can someone + // remind me what generic programming is about? -- Gaby + // Forward iterator requirements template<typename _IteratorL, typename _IteratorR, typename _Container> inline bool @@ -639,11 +652,23 @@ namespace std const __normal_iterator<_IteratorR, _Container>& __rhs) { return __lhs.base() == __rhs.base(); } + template<typename _Iterator, typename _Container> + inline bool + operator==(const __normal_iterator<_Iterator, _Container>& __lhs, + const __normal_iterator<_Iterator, _Container>& __rhs) + { return __lhs.base() == __rhs.base(); } + template<typename _IteratorL, typename _IteratorR, typename _Container> inline bool operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) - { return !(__lhs == __rhs); } + { return __lhs.base() != __rhs.base(); } + + template<typename _Iterator, typename _Container> + inline bool + operator!=(const __normal_iterator<_Iterator, _Container>& __lhs, + const __normal_iterator<_Iterator, _Container>& __rhs) + { return __lhs.base() != __rhs.base(); } // Random access iterator requirements template<typename _IteratorL, typename _IteratorR, typename _Container> @@ -652,30 +677,54 @@ namespace std const __normal_iterator<_IteratorR, _Container>& __rhs) { return __lhs.base() < __rhs.base(); } + template<typename _Iterator, typename _Container> + inline bool + operator<(const __normal_iterator<_Iterator, _Container>& __lhs, + const __normal_iterator<_Iterator, _Container>& __rhs) + { return __lhs.base() < __rhs.base(); } + template<typename _IteratorL, typename _IteratorR, typename _Container> inline bool operator>(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) - { return __rhs < __lhs; } + { return __lhs.base() > __rhs.base(); } + + template<typename _Iterator, typename _Container> + inline bool + operator>(const __normal_iterator<_Iterator, _Container>& __lhs, + const __normal_iterator<_Iterator, _Container>& __rhs) + { return __lhs.base() > __rhs.base(); } template<typename _IteratorL, typename _IteratorR, typename _Container> inline bool operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) - { return !(__rhs < __lhs); } + { return __lhs.base() <= __rhs.base(); } + + template<typename _Iterator, typename _Container> + inline bool + operator<=(const __normal_iterator<_Iterator, _Container>& __lhs, + const __normal_iterator<_Iterator, _Container>& __rhs) + { return __lhs.base() <= __rhs.base(); } template<typename _IteratorL, typename _IteratorR, typename _Container> inline bool operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) - { return !(__lhs < __rhs); } + { return __lhs.base() >= __rhs.base(); } + + template<typename _Iterator, typename _Container> + inline bool + operator>=(const __normal_iterator<_Iterator, _Container>& __lhs, + const __normal_iterator<_Iterator, _Container>& __rhs) + { return __lhs.base() >= __rhs.base(); } template<typename _Iterator, typename _Container> inline __normal_iterator<_Iterator, _Container> operator+(typename __normal_iterator<_Iterator, _Container>::difference_type __n, const __normal_iterator<_Iterator, _Container>& __i) { return __normal_iterator<_Iterator, _Container>(__i.base() + __n); } -} // namespace std +} // namespace __gnu_cxx #endif diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index b30ea09..5e2ea54 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -175,8 +175,9 @@ public: typedef _Tp value_type; typedef value_type* pointer; typedef const value_type* const_pointer; - typedef __normal_iterator<pointer, vector_type> iterator; - typedef __normal_iterator<const_pointer, vector_type> const_iterator; + typedef __gnu_cxx::__normal_iterator<pointer, vector_type> iterator; + typedef __gnu_cxx::__normal_iterator<const_pointer, vector_type> + const_iterator; typedef value_type& reference; typedef const value_type& const_reference; typedef size_t size_type; diff --git a/libstdc++-v3/include/bits/type_traits.h b/libstdc++-v3/include/bits/type_traits.h index 89e50f3..61bc436 100644 --- a/libstdc++-v3/include/bits/type_traits.h +++ b/libstdc++-v3/include/bits/type_traits.h @@ -322,13 +322,13 @@ template<typename _Tp> struct _Is_normal_iterator { }; // Forward declaration hack, should really include this from somewhere. -namespace std +namespace __gnu_cxx { template<typename _Iterator, typename _Container> class __normal_iterator; } template<typename _Iterator, typename _Container> -struct _Is_normal_iterator< std::__normal_iterator<_Iterator, _Container> > { +struct _Is_normal_iterator< __gnu_cxx::__normal_iterator<_Iterator, _Container> > { typedef __true_type _Normal; }; diff --git a/libstdc++-v3/src/concept-inst.cc b/libstdc++-v3/src/concept-inst.cc index 11e4a89..a467a81 100644 --- a/libstdc++-v3/src/concept-inst.cc +++ b/libstdc++-v3/src/concept-inst.cc @@ -50,11 +50,11 @@ namespace __gnu_cxx template void __aux_require_boolean_expr<bool>(bool const&); _Instantiate(_BidirectionalIteratorConcept< - std::__normal_iterator< std::locale::facet**, + __normal_iterator< std::locale::facet**, std::vector<std::locale::facet*,std::allocator<std::locale::facet*> > > > ); _Instantiate(_BidirectionalIteratorConcept< - std::__normal_iterator< unsigned*, + __normal_iterator< unsigned*, std::vector<unsigned, std::allocator<unsigned> > > > ); _Instantiate(_ConvertibleConcept<std::locale::facet*, std::locale::facet*> ); @@ -68,15 +68,15 @@ namespace __gnu_cxx _Instantiate(_InputIteratorConcept<std::locale::facet**> ); _Instantiate(_InputIteratorConcept< - std::__normal_iterator< std::locale::facet* const*, + __normal_iterator< std::locale::facet* const*, std::vector<std::locale::facet*,std::allocator<std::locale::facet*> > > > ); _Instantiate(_InputIteratorConcept< - std::__normal_iterator< std::locale::facet**, + __normal_iterator< std::locale::facet**, std::vector<std::locale::facet*,std::allocator<std::locale::facet*> > > > ); _Instantiate(_InputIteratorConcept< - std::__normal_iterator< unsigned*, + __normal_iterator< unsigned*, std::vector<unsigned, std::allocator<unsigned> > > > ); #ifdef _GLIBCPP_USE_WCHAR_T @@ -98,26 +98,26 @@ namespace __gnu_cxx _Instantiate(_LessThanComparableConcept<unsigned> ); _Instantiate(_Mutable_BidirectionalIteratorConcept< - std::__normal_iterator< std::locale::facet**, + __normal_iterator< std::locale::facet**, std::vector<std::locale::facet*,std::allocator<std::locale::facet*> > > > ); _Instantiate(_Mutable_BidirectionalIteratorConcept< - std::__normal_iterator< unsigned*, + __normal_iterator< unsigned*, std::vector<unsigned, std::allocator<unsigned> > > > ); _Instantiate(_Mutable_ForwardIteratorConcept< - std::__normal_iterator< std::locale::facet**, + __normal_iterator< std::locale::facet**, std::vector<std::locale::facet*,std::allocator<std::locale::facet*> > > > ); _Instantiate(_OutputIteratorConcept< std::locale::facet**, std::locale::facet*> ); _Instantiate(_OutputIteratorConcept< - std::__normal_iterator< std::locale::facet**, + __normal_iterator< std::locale::facet**, std::vector<std::locale::facet*, std::allocator<std::locale::facet* > > >, std::locale::facet* > ); - _Instantiate(_OutputIteratorConcept<std::__normal_iterator< + _Instantiate(_OutputIteratorConcept<__normal_iterator< unsigned*, std::vector<unsigned, std::allocator<unsigned> > >, unsigned> ); _Instantiate(_OutputIteratorConcept<std::ostreambuf_iterator< @@ -133,19 +133,19 @@ namespace __gnu_cxx _Instantiate(_RandomAccessIteratorConcept<char const*> ); _Instantiate(_RandomAccessIteratorConcept< - std::__normal_iterator<char const*, std::string> > ); + __normal_iterator<char const*, std::string> > ); _Instantiate(_RandomAccessIteratorConcept< - std::__normal_iterator<char*, std::string> > ); + __normal_iterator<char*, std::string> > ); #ifdef _GLIBCPP_USE_WCHAR_T _Instantiate(_RandomAccessIteratorConcept< - std::__normal_iterator<wchar_t const*, + __normal_iterator<wchar_t const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > ); _Instantiate(_RandomAccessIteratorConcept< - std::__normal_iterator<wchar_t*, + __normal_iterator<wchar_t*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > ); diff --git a/libstdc++-v3/src/string-inst.cc b/libstdc++-v3/src/string-inst.cc index 7ebc0c5..e812aa0 100644 --- a/libstdc++-v3/src/string-inst.cc +++ b/libstdc++-v3/src/string-inst.cc @@ -48,9 +48,17 @@ namespace std template class basic_string<C>; template S operator+(const C*, const S&); template S operator+(C, const S&); +} // namespace std + +namespace __gnu_cxx +{ + using std::S; template bool operator==(const S::iterator&, const S::iterator&); template bool operator==(const S::const_iterator&, const S::const_iterator&); +} +namespace std +{ // Only one template keyword allowed here. // See core issue #46 (NAD) // http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_closed.html#46 diff --git a/libstdc++-v3/testsuite/24_iterators/rel_ops.cc b/libstdc++-v3/testsuite/24_iterators/rel_ops.cc new file mode 100644 index 0000000..2c85396 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/rel_ops.cc @@ -0,0 +1,45 @@ +// 2002-04-13 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2002 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 20.2.1 Operators + +#include <utility> +#include <vector> + +using namespace std::rel_ops; + +// libstdc++/3628 +void test01() +{ + std::vector<int> v; + std::vector<int>::iterator vi; + + vi != v.begin(); + vi > v.begin(); + vi <= v.begin(); + vi >= v.begin(); +} + +int main() +{ + test01(); + return 0; +} + |