   incrementing list iterator
  Is there an equivalent of doing std::list<val>::iterator l_it;l_it += 2;l_it -= 4;etcWithout using ++ and --. I know that with vectors the above operations are valid but is there a way of doing the same with lists?Also, a second question, if I delete an element in a list that an iterator is pointing to, what happens to the iterator? Does it become invalid or does it now point to one of the adjacent elements?Thanks.   
  http://www.cplusplus.com/reference/std/iterator/It says += will work. I have never done it before, but did it not compile?When you delete an object the data is garbage. You can do:list<type>::iterator iter = YourList.begin();iter = YourList.erase(iter);*The erase function returns the next object in the list.   ;  No it doesn't compile :S. seed += (*oIt)->mTriangles.begin() + 1;1>c:\documents and settings\david\mis documentos\visual studio 2008\projects\marauders\dungeon\playstate.cpp(76) : error C2678: binary '+' : no operator found which takes a left-hand operand of type 'std::list<_Ty>::_Iterator<_Secure_validation>' (or there is no acceptable conversion)1>   with1>   [1>  _Ty=b2Vec2,1>  _Secure_validation=true1>   ]1>   c:\box2d\source\common\b2math.h(554): could be 'b2Vec2 operator +(const b2Vec2 &,const b2Vec2 &)'1>   c:\box2d\source\common\b2math.h(593): or  'b2Vec3 operator +(const b2Vec3 &,const b2Vec3 &)'1>   c:\box2d\source\common\b2math.h(616): or  'b2Mat22 operator +(const b2Mat22 &,const b2Mat22 &)'1>   while trying to match the argument list '(std::list<_Ty>::_Iterator<_Secure_validation>, int)'1>   with1>   [1>  _Ty=b2Vec2,1>  _Secure_validation=true1>   ]Thanks for the iter = YourList.erase(iter);   ;  IIRC you can write:std::advance(l_it, 2);std::advance(l_it, -4);For random access iterators, this will compile down to "+=" or "-=", but for list iterators it will compile to "while(n--) it++" or "while(n--) it--"std::distance uses the same technique to implement "it1 - it2" for both random-access and list iterators.   ;  seed += (*oIt)->mTriangles.begin() + 1;It is complaining about the '+' not '+='.Needs to be:seed = (*oIt)->mTriangles.begin();seed += 1;   ;Quote:Original post by Antonyml_it += 2;l_it -= 4;Hopefully you're aware that this approach is very inefficient on long lists.  To go back, say, 100 elements with a list is 100 operations (following 100 back pointers), whereas with a vector it would be just 1 operation (decreasing an index by 100).  If this concerns you and you aren't sure what to do about it, please say so.   ;  No, I wasn't aware of that, thanks. I'll be sticking to vectors, the reason I switched to lists to begin with was because I didn't want to lose my iterators. Didn't know you could do iter = erase(iter).   