
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. 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. Finally, splice the remaining element from the first list into the second, so they're both in the other list now. Presto, comparing the same two iterators is valid again. -- Chris