简体   繁体   English

比较C ++ STL列表迭代器

[英]compare C++ STL list iterators

I have a C++ STL list of objects in my app that is built on startup and never altered afterwards; 我的应用程序中有一个C ++ STL对象列表,它是在启动时构建的,之后从未改变过; is it the case that two independent iterators that point to the same list node always compare equal ? 是这样的情况,指向同一列表节点的两个独立迭代器总是比较相等吗?

Yes. 是。 One of the requirements for forward iterators is: 前向迭代器的要求之一是:

C++11 22.4.5/6: If a and b are both dereferenceable, then a == b if and only if *a and *b are bound to the same object. C ++ 11 22.4.5 / 6:如果ab都是可解除引用的,则a == b当且仅当*a*b绑定到同一个对象时。

All iterators over standard containers are (at least) forward iterators. 标准容器上的所有迭代器都是(至少)前向迭代器。

Yes, according to cplusplus.com: 是的,根据cplusplus.com:

http://www.cplusplus.com/reference/std/iterator/ForwardIterator/ http://www.cplusplus.com/reference/std/iterator/ForwardIterator/

Accepts equality/inequality comparisons. 接受平等/不平等比较。
Equal iterators imply the same element is pointed 等于迭代器意味着指向相同的元素

(I'm not really a fan of this site but I'd trust it here.) (我不是这个网站的粉丝,但我相信它。)


cppreference.com agrees and states more than that, namely all InputIterators (that can be read from) are EqualityComparable, see: cppreference.com同意并说明不止于此,即所有InputIterators(可以读取)都是EqualityComparable,请参阅:

http://en.cppreference.com/w/cpp/concept/InputIterator http://en.cppreference.com/w/cpp/concept/InputIterator

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM