`

c++ - revist the iterators in c++

    博客分类:
  • c++
c++ 
阅读更多

There are 5 kinds of iterators when ppls talk about iterator. The 5 categories of iterators are in the following types. 

 

 

  • InputIterator
  • OutputIterator
  • ForwardIterator
  • Bindirectional Iterator
  • RandomAccessIterator

Let's see what they are.

 

InputIterator

An InputIterator can be used to read the elements of a container but is not guaranteed to support writing to into a container. 

 

OutputIterator 

 

An output iterator is can be throught of as having the opposite functionality of an InputIterator; that is, it can be used to write into the elements of a container but is not guaranteed to support the reading of a container.

 

ForwardIterator

 

A Forward iterator can be used to read from and write to a container in one direction of traversal. Algorithms minimallly requiring a ForwardIterator include adjacent_find, swap_range() and replace..

 

BidirectionalIterator

 

A BidirectionalIterator reads from and writes to container in both directions, Generic algorithms minimally requires a BidirectionalIterator include inplace_merge(), next_permutation(), reverse()

 

RandomAccessIterator

 

A RandomAccessIterator, in additional to supporting all the functionality of a BidirectionalIterator , provides access to any position within the container in constant time. Generic algorithms requiring  a RandomAccessIterator include binary_search(), sort_heap(), and nth_element()

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics