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

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.

主站蜘蛛池模板: 临江市| 大理市| 桂平市| 毕节市| 冀州市| 宜兴市| 灵川县| 新晃| 枣强县| 中超| 宜兰市| 云和县| 五华县| 禹州市| 武城县| 读书| 新竹市| 长子县| 涞源县| 曲麻莱县| 庄浪县| 班戈县| 钟山县| 怀宁县| 高雄县| 农安县| 尼勒克县| 灵川县| 理塘县| 淮安市| 古蔺县| 浦北县| 浑源县| 韶关市| 德州市| 昌黎县| 新兴县| 天镇县| 河南省| 玛沁县| 玉龙|