P
PengYu.UT
I'm wondering is the standard defined behavior of past bound iterator.
In the following example it seems that afer first "--it", it point to
-1 index. I'm wondering if it is true independent of which STL
implementation that I am using.
#include <iostream>
#include <vector>
int main(int argc, char *argv[]) {
std::vector<int> v;
for(int i = 0; i < 10; ++ i) {
v.push_back(i);
}
std::vector<int>::iterator it = v.begin();
-- it;
-- it;
std::cout << *it << std::endl;
++ it;
std::cout << *it << std::endl;
++ it;
std::cout << *it << std::endl;
++ it;
std::cout << *it << std::endl;
}
The output:
0
0
0
1
In the following example it seems that afer first "--it", it point to
-1 index. I'm wondering if it is true independent of which STL
implementation that I am using.
#include <iostream>
#include <vector>
int main(int argc, char *argv[]) {
std::vector<int> v;
for(int i = 0; i < 10; ++ i) {
v.push_back(i);
}
std::vector<int>::iterator it = v.begin();
-- it;
-- it;
std::cout << *it << std::endl;
++ it;
std::cout << *it << std::endl;
++ it;
std::cout << *it << std::endl;
++ it;
std::cout << *it << std::endl;
}
The output:
0
0
0
1