A
Alexander Stippler
Hello,
the standard requires a type reverse_iterator. But in the form it is
required and implemented for all compilers I know, there is IMO something
missing, which is essential for its usage.
With normal iterators you can compare a const_iterator and an iterator for
equality, using reverse_iterator as is, you can't. I can understand the
reason, why it's not provided. But does reverse_iterator make sense this
way? A simple example:
std::vector<int> v;
std::vector<int>::const_reverse_iterator it;
for (it=v.rbegin(); it!=v.rend(); ++it) {}
This won't compile, since it and v.rend() have different types and no
operator!= is defined for those. Isn't it unnatural that I can do the same
loop as above traversing the vector forward and it is legal code, but by
inverting the traversal direction, I create illegal code?
Any experiences with reverse_iterators? What do you think?
regards,
alex
the standard requires a type reverse_iterator. But in the form it is
required and implemented for all compilers I know, there is IMO something
missing, which is essential for its usage.
With normal iterators you can compare a const_iterator and an iterator for
equality, using reverse_iterator as is, you can't. I can understand the
reason, why it's not provided. But does reverse_iterator make sense this
way? A simple example:
std::vector<int> v;
std::vector<int>::const_reverse_iterator it;
for (it=v.rbegin(); it!=v.rend(); ++it) {}
This won't compile, since it and v.rend() have different types and no
operator!= is defined for those. Isn't it unnatural that I can do the same
loop as above traversing the vector forward and it is legal code, but by
inverting the traversal direction, I create illegal code?
Any experiences with reverse_iterators? What do you think?
regards,
alex