I thought vector::end()
equals to any iterator beyond the vector size, but recently I realized that end() + 1 != end()
.
I experimented further with the following code compiled by g++
:
int main() {
vector<int> v(10);
cout << (v.end() - v.begin()) << endl; // 10
cout << (v.end() + 1 - v.begin()) << endl; // 11
cout << (v.end() + 1 == v.end()) << endl; // false
return 0;
}
It is like the iterator actually holds an array index under the hood.
So my question is: for vector
, is this well-defined or compiler-dependent?