Checking if an iterator is valid

后端 未结 11 546
耶瑟儿~
耶瑟儿~ 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

    if (iterator != container.end()) {
       iterator is dereferencable !
    }
    

    If your iterator doesnt equal container.end(), and is not dereferencable, youre doing something wrong.

提交回复
热议问题