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

  • Mastering the C++17 STL
  • Arthur O'Dwyer
  • 181字
  • 2021-07-08 10:20:22

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.

主站蜘蛛池模板: 金阳县| 乡宁县| 石景山区| 旺苍县| 察隅县| 伊金霍洛旗| 大宁县| 赫章县| 诸城市| 汉阴县| 天峻县| 永和县| 赤壁市| 大石桥市| 顺昌县| 清流县| 富阳市| 宝山区| 霍邱县| 淮阳县| 确山县| 南汇区| 平武县| 五常市| 时尚| 江口县| 万载县| 巴林左旗| 天全县| 汪清县| 兴山县| 侯马市| 庆安县| 白玉县| 玛多县| 柯坪县| 永寿县| 安溪县| 宿州市| 无极县| 太谷县|