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


scott snyder <snyder@fnal.gov> writes:

> >> 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.

Ah well, I got the test right in so far as I deliberately provided
this behaviour so I tested for it as well!  In the past I have seen
code (and probably written such code myself) that uses a
const_iterator to refer to a non-const container simply because the
const_iterator is not going to be used to change the container.  I
think such code can always be re-written to use an iterator. I just
didn't realise that

     std::vector<int> v;
     std::vector<int>::const_iterator i = v.begin();
     if ( i != v.end() )
     {
     }

is not strictly conforming.

Philip

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