I'm almost certain that I can rely on it, but just to be sure...
For example:
It iterates over the modified vector in my case. (even after changing some compiler options manually).Code:int main() { srand(time(nullptr)); std::vector<int> vi = {1,4,4,1,1}; for(auto x = vi.begin(); x!=vi.end(); x++) { int i=rand()%6; if(i==1||i==4) vi.push_back(i); } for(auto x:vi) std::cout<<x<<std::endl; }
Is that standard/portable behaviour or is the compiler free to stop iterating at the original end iterator ?
Does volatile solve anything if the later is the case ?



LinkBack URL
About LinkBacks




ush_back()' is called you may invalidate `x'. The iterator points to the old memory area owned by the `std::vector<???>'; the operation `std::vector<???>: