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

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:

主站蜘蛛池模板: 合水县| 葵青区| 偃师市| 红桥区| 丰城市| 金昌市| 酒泉市| 蓬莱市| 宜川县| 泰安市| 西峡县| 城步| 陆川县| 萨嘎县| 弥勒县| 华安县| 甘泉县| 博白县| 西城区| 松江区| 井冈山市| 临江市| 茂名市| 墨脱县| 文山县| 五家渠市| 张家口市| 平安县| 峨眉山市| 惠安县| 阳江市| 东海县| 图木舒克市| 三亚市| 调兵山市| 龙陵县| 廊坊市| 平度市| 郴州市| 绥棱县| 文水县|