Comparing default-constructed iterators with operator==

前端 未结 4 921
清歌不尽
清歌不尽 2021-01-02 03:21

Does the C++ Standard say I should be able to compare two default-constructed STL iterators for equality? Are default-constructed iterators equality-comparable?

I w

4条回答
  •  死守一世寂寞
    2021-01-02 04:04

    OK, I'll take a stab. The C++ Standard, Section 24.1/5:

    Iterators can also have singular values that are not associated with any container. [Example: After the declaration of an uninitialized pointer x (as with int* x;), x must always be assumed to have a singular value of a pointer. ] Results of most expressions are undefined for singular values; the only excep- tion is an assignment of a non-singular value to an iterator that holds a singular value.

    So, no, they can't be compared.

提交回复
热议问题