Question: Is typedef vector<iterator> itvec
a valid declaration?
One minute response: Not quite, because iterators can only be declared relative to a container type. You would need something like
This is, however, exceptionally dangerous programming, because the iterators intypedef std::vector<int> ivec;
typedef ivec::iterator ivec_iter;
typedef std::vector<ivec_iter> iveciter_vec;
iveciter_vec odd_elements;
odd_elements
are almost certainly going to be invalidated over time, and you have no way of recognizing when that happens.
Question: Would it be feasable to write code to implement unsupported operators in certain iterator types and make algorithm writing easier?
One minute response: It would, but you would be producing non-standard extensions to the library. Whether this should bother you or not is a harder question to answer.
Question: Why do I have to learn about forward, bidirectional iterators when I cannot declare them in my code? What is iterator invalidation?
One minute response: You declare generic iterators; containers provide specific ones. If you don't understand the difference between, say, bidirectional and random iterators, you'll become confused when you try to use an unsupported opration on the wrong iterator. Iterator invalidation is the analog to the dangling pointer problem.
Question: Does each element in a container have an iterator [?].
One minute response: Yes; and also, the phanotm elements at either end of a container also have iterators (end and rend).
Question: Is it a good idea to iterate through all elements of vectors of vectors uing two iterators, one for the smaller or internal vector, and one for the bigger one? What should I keep in mind if I decide to use that?
One minute response: With only one minute to answer, I don't want to get into whether or not it's a good idea, but you certainly can do it. I suspect that, if it were me, I would look for a diffent algorithm, one that wouldn't require that I do O(n2) work.
This page last modified on 16 July 2003.