C++迭代器运算符定义
有关迭代器运算符如何工作的“定义”的任何想法或链接?更准确地说:例如,必须实现运算符“==”和“!=”——它们是否必须比较它们所持有的数据的成员(恕我直言,这将是一个问题,因为迭代器一开始就不应该知道数据)?与 .end() 和 .start() 相比如何?对于指针迭代器:它只是地址检查吗?
很高兴听到您的想法或获得定义的链接。
any idea or link concerning the "definition" of how operators of iterators have to work? To be more exact: How excatly do, for instance, operators "==" and "!=" have to be implemented -- do they have to compare members of the data they hold (which imho would be a problem, as the iterator should not know about the data in the first place)? How do you compare to .end() and .start()? For pointer iterators: is it just an address check?
Would be glad to hear about your ideas or get a link to the definition.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你需要阅读这样的内容: http://stdcxx.apache.org/doc /stdlibref/iterators.html
运算符
==
和!=
比较迭代器,而不是它们引用的数据。I think you need to read something like this: http://stdcxx.apache.org/doc/stdlibref/iterators.html
The operators
==
and!=
compare the iterators, not the data they refer to.原始的STL有一个关于迭代器的设计文档。
简而言之,它们是指针的泛化,因此
==
应该检查两个迭代器是否指向同一个容器中的同一个项目。指针迭代器确实应该在其指针比较时相等。与
begin()
或rbegin()
相比应该是微不足道的;与end()
或rend()
的比较可以通过多种方式完成,例如使其成为等于size()
的索引一个容器。The original STL has a design document on iterators.
In short, they are a generalization of pointers, so
==
should check whether two iterators point at the same item in the same container. Pointer iterators should indeed compare equal when their pointers do.Comparing to a
begin()
orrbegin()
should be trivial; comparing to anend()
orrend()
can be done in various ways, like making it an index equal to thesize()
of a container.== 和 != 运算符不会比较内容,它们只是检查两个迭代器是否引用同一个对象。
The == and != operators aren't expected to compare the contents, they merely check whether two iterators refer to the same object.