This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: problems with vector::iterator: 1



>this didn't make it to the list. Please feel free to re-post or reply to 
>the mailing list, as that way the discussion will be logged.

Yeah, a couple of the machines feeding into the site mail forwarder
are on the open relay blacklist, so i have to go though some contortions
to get mail past the filter.

>> Perhaps the real problem is that vector::iterator is implementing
>> behavior beyond what is specified in the standard.  I run into trouble
>> with the example i gave because different vector::iterator types
>> are comparable with each other.  But i don't see anything in the
>> standard which requires that functionality.  [Ok, it's a little hazy,
>> since in tables 72--76, i can't find any statements about what the
>> types of `a' and `b' are supposed to be.  But in the absence of any
>> statement, i think the only reasonable assumption is that they are both
>> of type `X'.]  So if the relational operators on __normal_iterator
>
>24.1 p 9
>
>"a and b denote values of X," so your assumption is correct

Ah, now i see it.  Thanks for pointing that out.

>And yes, I think you are correct. Can you try the following?
>
>Take out the current (incorrect) 3-parameter template operators  and put in 
>yours, run  the testsuite, and see if everything is ok? If so, send the 
>patch and I'll check it in.

Ok, i tried that, and found that one of the tests was explicitly
changing this functionality: 24_iterators/iterator.cc was comparing
iterator and const_iterator from vector and string.

If i comment out those tests from that file, then the results
of the testsuite are unchanged.  [I do however see a number of testsuite
failures even before i make the change.]


Here are the diffs:

1999-11-11  Scott Snyder  <snyder@fnal.gov>

	* stl/bits/stl_iterator.h: Change the relational operators
        on __normal_iterator so that their two arguments must be
        of the same type.  This is in line with the C++ standard,
        and it resolves a conflict with the generic definitions
        in rel_ops.
        * testsuite/24_iterators/iterator.cc: Comment out the tests
        attempting to compare iterators of unlike types.

Index: stl/bits/stl_iterator.h
===================================================================
RCS file: /cvs/libstdc++/libstdc++/stl/bits/stl_iterator.h,v
retrieving revision 1.19
diff -u -p -r1.19 stl_iterator.h
--- stl_iterator.h	1999/06/16 01:46:12	1.19
+++ stl_iterator.h	1999/11/11 23:25:09
@@ -1056,36 +1056,36 @@ protected:
 
 // forward iterator requirements
 
-template<typename _IteratorL, typename _IteratorR, typename _Container>
-bool operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
-                const __normal_iterator<_IteratorR, _Container>& __rhs)
+template<typename _Iterator, typename _Container>
+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>
-bool operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs,
-                const __normal_iterator<_IteratorR, _Container>& __rhs)
+template<typename _Iterator, typename _Container>
+bool operator!=(const __normal_iterator<_Iterator, _Container>& __lhs,
+                const __normal_iterator<_Iterator, _Container>& __rhs)
 { return !(__lhs == __rhs); }
 
 // random access iterator requirements
 
-template<typename _IteratorL, typename _IteratorR, typename _Container>
-bool operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
-               const __normal_iterator<_IteratorR, _Container>& __rhs)
+template<typename _Iterator, typename _Container>
+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>
-bool operator>(const __normal_iterator<_IteratorL, _Container>& __lhs,
-               const __normal_iterator<_IteratorR, _Container>& __rhs)
+template<typename _Iterator, typename _Container>
+bool operator>(const __normal_iterator<_Iterator, _Container>& __lhs,
+               const __normal_iterator<_Iterator, _Container>& __rhs)
 { return __rhs < __lhs; }
 
-template<typename _IteratorL, typename _IteratorR, typename _Container>
-bool operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
-                const __normal_iterator<_IteratorR, _Container>& __rhs)
+template<typename _Iterator, typename _Container>
+bool operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
+                const __normal_iterator<_Iterator, _Container>& __rhs)
 { return !(__rhs < __lhs); }
 
-template<typename _IteratorL, typename _IteratorR, typename _Container>
-bool operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs,
-                const __normal_iterator<_IteratorR, _Container>& __rhs)
+template<typename _Iterator, typename _Container>
+bool operator>=(const __normal_iterator<_Iterator, _Container>& __lhs,
+                const __normal_iterator<_Iterator, _Container>& __rhs)
 { return !(__lhs < __rhs); }
 
 template<typename _Iterator, typename _Container>


Index: testsuite/24_iterators/iterator.cc
===================================================================
RCS file: /cvs/libstdc++/libstdc++/testsuite/24_iterators/iterator.cc,v
retrieving revision 1.2
diff -u -p -r1.2 iterator.cc
--- iterator.cc	1999/07/14 09:32:51	1.2
+++ iterator.cc	1999/11/11 23:25:09
@@ -218,6 +218,7 @@ int string_stuff()
 
    // iterator and const_iterator
    std::string::const_iterator ci4(i1);
+#if 0
    if ((ci4 == i1) != true)
       ++failures;
    if ((ci4 != i1) != false)
@@ -241,6 +242,7 @@ int string_stuff()
      ++failures;
    if ((i2 >= ci4) != true)
      ++failures;
+#endif
 
    const std::string cs("ABCDE");
    std::string::const_iterator ci5(cs.begin());
@@ -449,6 +451,7 @@ int vector_stuff()
 
    // iterator to const_iterator
    std::vector<int>::const_iterator ci4(i1);
+#if 0
    if ((ci4 == i1) != true)
       ++failures;
    if ((ci4 != i1) != false)
@@ -472,6 +475,7 @@ int vector_stuff()
      ++failures;
    if ((i2 >= ci4) != true)
      ++failures;
+#endif
 
    const std::vector<int> cv(v);
    std::vector<int>::const_iterator ci5(cv.begin());

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]