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

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

主站蜘蛛池模板: 桃江县| 全椒县| 阆中市| 平昌县| 台前县| 武夷山市| 绥中县| 甘泉县| 灌南县| 天峻县| 灵山县| 通榆县| 昆明市| 宁德市| 威信县| 涞源县| 成武县| 揭阳市| 荃湾区| 卢氏县| 青神县| 岚皋县| 宝丰县| 进贤县| 武夷山市| 吉水县| 郎溪县| 南平市| 思南县| 中江县| 工布江达县| 齐齐哈尔市| 青州市| 冷水江市| 得荣县| 哈密市| 教育| 平南县| 光山县| 南靖县| 特克斯县|