简体   繁体   English

输入迭代器+输出迭代器+ X =正向迭代器

[英]input iterator + output iterator + X = forward iterator

I want to solve the equation in the title and find X. As far as I understand, an input or output iterator, unlike a forward iterator, gets invalidated as soon as a copy of it is advanced. 我想求解标题中的方程并找到X。据我所知,与正向迭代器不同,输入或输出迭代器在其副本被推进时就失效了。 Is there any additional requirement in order for a type T which satisfies both input iterator concept and output iterator concept to satisfy the forward iterator concept? 对于满足输入迭代器概念和输出迭代器概念的T类型以满足正向迭代器概念,是否还有其他要求?

In any case, can you provide a real-world example of an iterator which is both input and output but is not forward? 无论如何,您能否提供迭代器的真实示例,它既是输入又是输出,而不是正向? Thanks 谢谢

Iterator categories deal with operations allowed on an iterator. 迭代器类别处理在迭代器上允许的操作。 Dereferencing forward iterator must yield T& (C++03) while dereferencing input iterator must only yield a type convertible to T . 取消引用正向迭代器必须产生T& (C ++ 03),而取消引用输入迭代器必须只能产生可转换为T的类型。 As an example, vector<bool>::iterator is an input/output iterator, but not a forward iterator (because dereferencing it returns a proxy convertible to bool — because you can't return a reference to a bit). 例如, vector<bool>::iterator是一个输入/输出迭代器,但不是正向迭代器(因为取消引用它会返回可转换为bool的代理-因为您无法返回对位的引用)。

并且根据此处的图表可以默认构造正向迭代器,但不能构造输入或输出迭代器。

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

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