简体   繁体   English

迭代器的类型:输出与输入与前向与随机访问迭代器

[英]Types of iterator : Output vs. Input vs. Forward vs. Random Access Iterator

How many types of iterators are there in C++ STL? C ++ STL中有多少种类型的迭代器? As of now, I know of these: 截至目前,我知道这些:

  • Output Iterator 输出迭代器
  • Input Iterator 输入迭代器
  • Forward Iterator 转发迭代器
  • Random Access Iterator 随机访问迭代器

Are there more? 还有更多吗? What are the differences between them? 它们之间有什么区别? What are the limitations and characteristics of each? 每个的限制和特征是什么? Which type is used when? 使用哪种类型?

If you can, find and read "The C++ Standard Library: A Tutorial and Reference". 如果可以,请查找并阅读“The C ++ Standard Library:A Tutorial and Reference”。 This book contains a whole chapter about STL iterators. 本书包含有关STL迭代器的整章。

Here is a little something from the book: 这是书中的一些内容:

Iterator Category  Ability                          Providers
-----------------  -------------------------------  ----------------------------
Input iterator     Reads forward                    istream
Output iterator    Writes forward                   ostream, inserter
Forward iterator   Reads/writes forward             forward_list,
                                                      unordered_[multi]set,
                                                      unordered_[multi]map
Bidirectional it.  Reads/writes forward/backward    list, [multi]set, [multi]map
Random access it.  Reads/writes with random access  vector, deque string, array 

The C++ standard also has a Bidirectional Iterator concept, which is a Forward Iterator that can also go backward (with operator-- ). C ++标准还有一个双向迭代器概念,它是一个前向迭代器,也可以向后(使用operator-- )。 Together, these five form the entire iterator hierarchy in paragraph 24.2 of the C++ standard. 这五个一起构成了C ++标准第24.2节中的整个迭代器层次结构。

The old STL also had the concept of a Trivial Iterator . 旧的STL也有一个简单的迭代器的概念。 See its Iterator overview for details regarding the various iterators. 有关各种迭代器的详细信息,请参阅其迭代器概述

Boost designers Abrahams, Siek and Witt have presented a much more fine-grained set of iterator concepts. 提升设计师Abrahams,Siek和Witt 提出了一系列更精细的迭代器概念。

我怀疑你很清楚答案,但无论如何, 这些图表对于解决这个问题非常有帮助

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

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