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

  • 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:

主站蜘蛛池模板: 通河县| 札达县| 图片| 玉溪市| 清原| 四会市| 卢氏县| 渭源县| 济源市| 丹东市| 望奎县| 常州市| 如皋市| 九龙坡区| 同德县| 犍为县| 牙克石市| 武定县| 镇康县| 闻喜县| 郯城县| 南木林县| 朝阳县| 苏尼特右旗| 准格尔旗| 太和县| 栖霞市| 那曲县| 东阳市| 泾源县| 贡觉县| 南平市| 渑池县| 永福县| 普安县| 尉氏县| 太仆寺旗| 甘南县| 交口县| 清苑县| 嘉祥县|