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

Summary

In this chapter, we've learned that traversal is one of the most fundamental things you can do with a data structure. However, raw pointers alone are insufficient for traversing complicated structures: applying ++ to a raw pointer often doesn't "go on to the next item" in the intended way.

The C++ Standard Template Library provides the concept of iterator as a generalization of raw pointers. Two iterators define a range of data. That range might be only part of the contents of a container; or it might be unbacked by any memory at all, as we saw with getc_iterator and putc_iterator. Some of the properties of an iterator type are encoded in its iterator category--input, output, forward, bidirectional, or random-access--for the benefit of function templates that can use faster algorithms on certain categories of iterators.

If you're defining your own container type, you'll need to define your own iterator types as well--both const and non-const versions. Templates are a handy way to do that. When implementing your own iterator types, avoid the deprecated std::iterator, but consider boost::iterator_facade.

主站蜘蛛池模板: 巨野县| 闻喜县| 府谷县| 亚东县| 乐清市| 桦川县| 务川| 开远市| 南昌市| 安岳县| 石城县| 娱乐| 新宁县| 奉新县| 马尔康县| 昌图县| 昂仁县| 中阳县| 南安市| 弥勒县| 西青区| 肇庆市| 石嘴山市| 博罗县| 灵川县| 托克逊县| 黄山市| 咸宁市| 田林县| 瑞安市| 铜陵市| 洞口县| 桑植县| 灵川县| 湘阴县| 高安市| 西乌珠穆沁旗| 三穗县| 忻城县| 苏尼特左旗| 集安市|