输入迭代器和只读前向迭代器之间有什么区别? [英] What's the difference between input iterators and read-only forward iterators?

查看:122
本文介绍了输入迭代器和只读前向迭代器之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入迭代器和只读前向迭代器之间有什么区别?

What's the difference between input iterators and read-only forward iterators?

因为后者是只读的,所以它们显然不满足输出迭代器的要求。而且,正因为如此,它们才能有效地输入迭代器并提供额外的保证(如果有的话)。问题是,有什么额外保证?

Because the latter are read-only, they obviously don't satisfy requirements of output iterators. And, because of that, they're effectively input iterators with additional guarantees (if any). The problem is, what additional guarantees?

我的猜测是前向迭代器是多次传递而输入迭代器不是,我是对的吗?

My guess would be that forward iterators are multi-pass and input iterators are not, am I right?

推荐答案

是的,输入迭代器是一遍迭代器。你只能迭代它们一次,而前向迭代器是多遍的。

Yes, input iterators are one-pass iterators. You can only iterate over them once, while forward iterators are multi-pass.

来自§24.2.3[input.iterators] p2(表)的前/后条件列+ r


pre: r 是可解除引用的。

post: r 是可解除引用的或 r 是过去的结果。

发布: r 不再需要可解除引用或位于 == 的域中。

pre: r is dereferenceable.
post: r is dereferenceable or r is past-the-end.
post: any copies of the previous value of r are no longer required either to be dereferenceable or to be in the domain of ==.

最后一个后置条件暗示对于 a == b ++ a == ++ b 不需要 true

相同条款,第3段:

The last postcondition implies that for a == b, ++a == ++b is not required to be true.
Same clause, paragraph 3:


[注意:对于输入迭代器, a == b 并不意味着 ++ a == ++ b'/ em>的。 (Equality不保证替换属性或引用透明性。)输入迭代器上的算法绝不应该尝试两次通过相同的迭代器。它们应该是单通算法。 [...]这些算法可以通过 istream_iterator 类模板与istreams一起用作输入数据的来源。 -end note ]

[ Note: For input iterators, a == b does not imply ++a == ++b. (Equality does not guarantee the substitution property or referential transparency.) Algorithms on input iterators should never attempt to pass through the same iterator twice. They should be single pass algorithms. [...] These algorithms can be used with istreams as the source of the input data through the istream_iterator class template. —end note ]

来自§24.2.5[forward.iterators]


p1类或指针类型 X 满足如果


  • [...]

  • 类型<$的对象,则需要前向迭代器c $ c> X 提供多次通过保证,如下所述。

  • [...]
  • objects of type X offer the multi-pass guarantee, described below.

p3两个可解除引用的迭代器a和 c 类型的b提供多次通过保证如果:

p3 Two dereferenceable iterators a and b of type X offer the multi-pass guarantee if:


  • a == b 暗示 ++ a == ++ b

  • X 是指针类型或表达式(void)++ X(a),* a 相当于表达式 * a

  • a == b implies ++a == ++b and
  • X is a pointer type or the expression (void)++X(a), *a is equivalent to the expression *a.

这篇关于输入迭代器和只读前向迭代器之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆