c++ - std::advance - offset out of range failure on Debug only -


i'm trying iterate through vector more 1 using std::advance. there's discrepancy between debug , release builds debug giving vector iterator + offset out of range failure while release works in real application in more expanded case. why happen , how can write runs on debug?

vector<glm::vec2> testv; testv.push_back(glm::vec2(0.f)); int step = 2;  (auto = testv.begin(); != testv.end(); ) {     if (it + step <= testv.end())         advance(it, step);      else         ++it; } 

this runs on release (unless print in loop causes hang)

for (auto = testv.begin(); != testv.end(); )     advance(it, step); 

the addition operator iterator validating returned iterator. when add 2 , go past end, generate error in debug. release build doesn't have these checks doesn't report problem.

having iterator point past end of container is, think undefined behavior. dereferencing is.

you'll have check going past end other way.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -