Get access to members through iterators

Started by
11 comments, last by Zahlman 17 years, 6 months ago
Quote:Original post by phil_t
I've never tried it, but vector's iterator is supposed to be a random access iterator... you should be able to do both ++ and -- with it, no?

Yeah, the only thing is that I can't stop at the first element when traversing backwards. Since end() returns a pointer beyond the last element but begin() at the first. I can solve this by handling my own dummy.
Advertisement
Well, if you're *just* traversing backwards, it's no problem... just use reverse_iterator, rbegin() and rend().

IIRC, you can construct a reverse_iterator from a corresponding iterator explicitly, and you can convert a reverse_iterator back into a normal iterator with .base() (you'll probably want to check the exact semantics on that one, though).

This topic is closed to new replies.

Advertisement