2

Suppose I have an iterator std::list::iterator it = mylist.begin() of a container, and I call

iterator it2 = std::next(it,1);

Does std::next check if it == mylist.end()?

Tas
  • 7,023
  • 3
  • 36
  • 51
Andrea Araldo
  • 1,332
  • 14
  • 20
  • you means to say it != mylist.end() .no it doesn't check – Hariom Singh Aug 17 '17 at 00:20
  • The behavior is undefined if the specified sequence of increments or decrements would require that a non-incrementable iterator (such as the past-the-end iterator) is incremented, or that a non-decrementable iterator (such as the front iterator or the singular iterator) is decremented. – Hariom Singh Aug 17 '17 at 00:22

1 Answers1

1

No, the program was blocking in that situation. You should check yourself:

if (it != mylist.end())
    it2 = std::next(it,1);
Andrea Araldo
  • 1,332
  • 14
  • 20