Checking if an iterator is valid

后端 未结 11 540
耶瑟儿~
耶瑟儿~ 2020-11-30 02:52

Is there any way to check if an iterator (whether it is from a vector, a list, a deque...) is (still) dereferencable, i.e. has not been invalidated?

I have been usi

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 03:23

    use erase with increment :

       if (something) l.erase(itd++);
    

    so you can test the validity of the iterator.

提交回复
热议问题