In theory, there is a way if the considered iterator is at least the front iterator. You can check if your iterator is one of the iterators in the [first, last] for each candidate container. Since you are using a vector container, you have a random access iterator, you can use a smaller operator to quickly perform this check.
You need to know all the candidate vectors with which you need to check the front, and this is not a general way to get the container to which the iterator belongs.
However, you can define the extension of random access iterators by decorating a random access iterator with something containing a pointer to the creating vector. It will probably be a little inelegant, inefficient and uncomfortable. See if you can rewrite the code to avoid this need.
Thomas Kammeyer
source share