What happens if you increment an iterator that is equal to the end iterator of an STL container

前端 未结 8 1429
别那么骄傲
别那么骄傲 2020-11-27 05:46

What if I increment an iterator by 2 when it points onto the last element of a vector? In this question asking how to adjust the iterator to an STL container by 2 elements t

相关标签:
8条回答
  • 2020-11-27 06:45

    The code that Marijn suggests is just slightly wrong (as curiousguy pointed out).

    The correct version of the last line is:

    bool isPastEnd = it >= vec.end();
    
    0 讨论(0)
  • 2020-11-27 06:46

    I suggest you to take a look at Boost.Range.
    It might be safer to use.
    It will also be in C++0x.

    0 讨论(0)
提交回复
热议问题