Vector End Iterators

Possible duplicate:
comparing iterators from different containers

In practice, std::vector<T>::iterator is probably implemented as a wrapped T* for most STL implementations, so each iterator is associated with a unique memory address (if the iterator comes from a non-empty vector).

However, this implementation detail. Is there a real guarantee from the C ++ standard that every vector iterator is somehow unique? In particular, can the end() tetra of one nonempty vector ever equal the end() iterator of another nonempty vector?

For instance:

 std::vector<int> v1; std::vector<int> v2; /* Fill both vectors with values... */ assert(v1.end() != v2.end()); // Does C++ guarantee this assertion will succeed? 
+4
source share
1 answer

Vectors cannot intersect, so the end of one non-empty container cannot just be the end of another non-empty container. The end of one vector, apparently, can be equal to the end of another empty vector. But I don’t think you are allowed to compare iterators in different containers, so that doesn’t really matter.

+1
source

Source: https://habr.com/ru/post/1341460/


All Articles