官术网_书友最值得收藏!

  • Mastering C++ Programming
  • Jeganathan Swaminathan
  • 168字
  • 2021-07-02 18:28:48

Iterators

An iterator is a design pattern, but interestingly, the STL work started much before
Gang of Four published their design patterns-related work to the software community. Iterators themselves are objects that allow traversing the containers to access, modify, and manipulate the data stored in the containers. Iterators do this so magically that we don't realize or need to know where and how the data is stored and retrieved.

The following image visually represents an iterator:

From the preceding image, you can understand that every iterator supports the begin() API, which returns the first element position, and the end() API returns one position past the last element in the container.

The STL broadly supports the following five types of iterators:

  • Input iterators
  • Output iterators
  • Forward iterators
  • Bidirectional iterators 
  • Random-access iterators

The container implements the iterator to let us easily retrieve and manipulate the data, without delving much into the technical details of a container. 

The following table explains each of the five iterators:

主站蜘蛛池模板: 深泽县| 江山市| 新平| 延川县| 哈尔滨市| 棋牌| 汤原县| 上林县| 乌审旗| 惠安县| 广南县| 闵行区| 内黄县| 普定县| 克拉玛依市| 江永县| 山阳县| 新建县| 万盛区| 弥渡县| 尼木县| 万源市| 来宾市| 常德市| 蕉岭县| 重庆市| 嘉禾县| 新沂市| 铅山县| 二连浩特市| 原平市| 新竹市| 鸡泽县| 长白| 昌黎县| 株洲市| 翁牛特旗| 托克逊县| 永泰县| 二连浩特市| 汶川县|