Skip to content

Commit

Permalink
[faq] 说明迭代器的设计来源
Browse files Browse the repository at this point in the history
  • Loading branch information
FeignClaims committed Feb 5, 2024
1 parent bda5959 commit 0287a1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/_static/links.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
.. _`Bjarne Stroustrup's C++ Glossary`: https://www.stroustrup.com/glossary.html
.. _`《Sixteen Ways to Stack a Cat》by Bjarne Stroustup`: https://gitee.com/cpp_tutorial/weekly_question/raw/master/src/extra/16%E7%A7%8D%E6%96%B9%E5%BC%8F%E6%8A%8A%E4%B8%80%E5%8F%AA%E7%8C%AB%E6%94%BE%E5%85%A5%E6%A0%88%E4%B8%AD.pdf
.. _`《The C++ Standard Library》补充章节`: http://www.cppstdlib.com/cppstdlib_supplementary.pdf
.. _`《Effecient Programming with Components》`: https://www.jmeiners.com/efficient-programming-with-components/index.html

.. _`Conan 2.0 Documentation`: https://docs.conan.io/2/
.. _`Clang-Format 官方文档`: https://clang.llvm.org/docs/ClangFormat.html
Expand Down
22 changes: 16 additions & 6 deletions docs/faq/range_iterator_and_algorithm/main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,6 @@
Forward_list_iterator(&node2))
}
.. hint::

考虑到你可能没学习链表, 我先通过数组和指针给出了迭代器概念, 再用链表强调迭代器概念, 这看起来好像迭代器概念凭空而来, 又恰好能用于链表.

但请不要误会, 《Elements of Programming》(《编程原本》) 和 `STL and Its Design Principles - Alexander Stepanov`_ 都明确解释了, 各种概念是根据对大量已有数据结构和算法的观察才抽象出来的. 也就是说先有了对数组、链表等等数据结构的观察, 才抽象出了迭代器概念, 而这种精心设计的概念基于数学理论能应用于更多方面——这与抽象代数从其他数学领域中抽象得到是相通的.

========================================================================================================================
算法 (algorithm)
========================================================================================================================
Expand Down Expand Up @@ -1174,6 +1168,22 @@ TODO, 没想到好的解释.
return find_last_impl(begin, end, value, Iter::iterator_category());
}
========================================================================================================================
关于迭代器的设计
========================================================================================================================

考虑到你可能没学习链表, 本解释中我先通过数组和指针给出了迭代器概念, 再用链表强调迭代器概念, 这看起来好像迭代器概念凭空而来, 又恰好能用于链表.

但请不要误会, 《Elements of Programming》(《编程原本》) 和 `STL and Its Design Principles - Alexander Stepanov`_ 都明确解释了, 各种概念是根据对大量已有数据结构和算法的观察才抽象出来的. 也就是说先有了对数组、链表等等数据结构的观察, 才抽象出了迭代器概念, 而这种精心设计的概念基于数学理论能应用于更多方面——这与抽象代数从其他数学领域中抽象得到是相通的.

其他语言也存在迭代器, 但 C++ 的迭代器与它们来自不同的概念.

.. epigraph::

我们的迭代器是对数据结构中坐标的一种泛化, 是一种轻量级的东西: 它不做任何事情, 只是指向某些东西.

—— Alexander Stepanov `《Effecient Programming with Components》`_

========================================================================================================================
涉及的标准库内容
========================================================================================================================
Expand Down

0 comments on commit 0287a1d

Please sign in to comment.