Hi I have situation on windows 10, that declared empty class member variable vector, but this vector\'s begin()(first iterator)
and end()(last iterator)
The standard only requires that the iterators are equal, not that their adresses are the same. Considering the adresses of iterators is pointless.
As other have stated, the two iterators are different objects, so they need to have different adresses.
For reference, see this answer.
The iterators are returned by value, so the address will indeed not be the same. Even if you do:
const vector<whatever>::iterator &it1 = vect.begin();
const vector<whatever>::iterator &it2 = vect.begin();
the addresses of it1
and it2
can be different (and will be in many implementations) - even if references are used.
(note that using begin()
in both is not a mistake - the same method begin()
will return two different objects with different values)
std::vector<int> v;
assert(v.begin() == v.end());
This should work: begin and end compare equal.
On the other hand
auto b = v.begin();
auto e = v.end();
assert(&b == &e);
is prohibited from working: the two iterators are different objects and must have different addresses.
Compare the equivalent:
int i = 42;
int j = 42;
assert(i == j); // ok
assert(&i == &j); // fail