《STL Tutorial Reference》 Chapt 7 Iterators
Chapt 7 Iterators
7.1 头文件
每个容器都定义它们自己的iterator类型,因此通常你不需要特殊的头文件来使用iterator。但是有几种特殊的iterator,例如reverse iteratos,它们被定义在<iteraor>头文件中。同样,你也不需要自己包含此头文件,它们已经被容器包含以定义它们自己的特定iterator
7.2 Iterator Categories
Iterator Category | Ability | Provider |
Input iterator | Read, forward | istream |
Output iterator | Write, forward | ostream, inserter |
Forward iterator | Read/write, forward | |
Bidirectional iterator | Read/write, forward/backward | list, set/multiset,map/multimap |
Rabdin access iterator | Read/write, random access | vector, deque,string,array |
7.2.1 Input iterators
支持的操作:
操作 | Input iterator | Output iterator | Forward Iterator | Bidirectional iterator | Random access iterator |
*iter | √ | √ | √ | √ | |
iter->member | √ | √ | √ | √ | |
*iter = value | √ | √ | √ | √ | |
iter1 = iter2 | √ | √ | √ | ||
++iter | √ | √ | √ | √ | √ |
iter++ | √ | √ | √ | √ | √ |
--iter | √ | √ | |||
iter-- | √ | √ | |||
iter1==iter2 | √ | √ | √ | √ | |
iter1!=iter2 | √ | √ | √ | √ | |
iter[n] | √ | ||||
iter += n | √ | ||||
iter -= n | √ | ||||
iter + n | √ | ||||
n + iter | √ | ||||
iter - n | √ | ||||
iter1 - iter2 | √ | ||||
iter1 < iter2 | √ | ||||
iter1 > iter2 | √ | ||||
iter1 <= iter2 | √ | ||||
iter1 >= iter2 | √ | ||||
TYPE(iter) | √ | √ | √ | √ | √ |