简体   繁体   English

C ++迭代器相等

[英]C++ iterator equality

How does c++ std library implement for example, vector iterators? c ++ std库如何实现例如矢量迭代器? It allows you to do equality testing on a regular iterator and a reverse iterator, what kind of design allows this to be possible? 它允许您在常规迭代器和反向迭代器上进行相等性测试,哪种设计可以做到这一点?

Edit: So below someone responded with the actual code of overloaded == method, which is not what i'm looking for, so maybe the scope of this question wasn't clear. 编辑:因此,下面有人用重载的==方法的实际代码进行了响应,这不是我要查找的内容,因此,这个问题的范围尚不清楚。 What I mean by "how does the std library implement vector iterators" is more of a design level question of what kind of inheritance tree does the iterator class use, what were some design trade-offs with doing it that way, other alternative designs, etc. If someone could shed some light on this that would be great. 我的意思是“标准库如何实现矢量迭代器”,更多的是设计级别的问题,即迭代器类使用哪种继承树,以这种方式进行设计时需要进行哪些取舍,其他替代设计,等等。如果有人可以对此有所启示,那将是很好。

This is from <vector> : 这来自<vector>

bool operator==(const _Myiter& _Right) const
    {   // test for iterator equality
        _Compat(_Right);
         return (this->_Ptr == _Right._Ptr);
    }

The iterator contains a pointer _Ptr as a member. 迭代器包含一个指针_Ptr作为成员。 This is typical of all iterators. 这是所有迭代器的典型特征。 They are wrappers to a reference into the collection. 它们是对集合中引用的包装。

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

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