
On Feb 9, 2005, at 3:36 PM, Chris Uzdavinis wrote:
Doug Gregor <dgregor@cs.indiana.edu> writes:
No, it is not legal to compare iterators from different containers. Operations that require two iterators mandate that the iterators be part of the operation's "domain". Iterators from different containers can never be in the same domain.
I generally agree, but think it gets a bit murky when we deal with std::list iterators, since they can be spliced back and forth between different containers without being invalidated.
Splice essentially transfers ownership of iterations from one container to another...
It seems strange that we can compare the two iterators into a list and that's valid. Then splice one element into another list--the iterators have not changed whatsoever--but now comparing them is invalid.
Sure, but I can do this, too: vector<int> v1, v2; vector<int>::iterator i, j; i = v1.begin(); j = v1.end(); i == j; i = v2.begin(); j = v2.end(); i == j; The domain changed for both iterators, just like in the list example. Domains are not static properties, and this is _really_ important. It shows up in the stream iterators, too, where the specifications of != and == make absolutely no sense without careful considering the domain of the operations. Doug