我在哪里可以获得 C++ 的示例代码为我自己的容器创建迭代器?

发布于 2024-08-11 01:00:32 字数 222 浏览 3 评论 0原文

我一直在寻找为我自己的容器创建迭代器的示例代码,但我还没有真正找到一个好的例子。我知道以前有人问过这个问题(创建我自己的迭代器),但没有看到任何满意的答案并举例说明。

我正在寻找简单的示例代码来开始如何设计我自己的迭代器。

谢谢

I have been searching for sample code creating iterator for my own container, but I haven't really found a good example. I know this been asked before (Creating my own Iterators) but didn't see any satisfactory answer with examples.

I am looking for simple sample code to start how to design my own iterator.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

森林很绿却致人迷途 2024-08-18 01:00:32

在这里您可以找到有关创建自定义迭代器的良好介绍。另请查看 Boost.Iterator图书馆。

Here you could find good intro for creating custom iterators. Also take a look on the Boost.Iterator Library.

策马西风 2024-08-18 01:00:32

我发现 Matthew Wilson 的“扩展 STL”非常主题。包含大量注意事项,以及大量实用的编程技巧。我认为这个人真的知道他在做什么。 (也为此创建了库)

I found Matthew Wilson's 'extended STL' very educative on the subject. Contains lots of do's and don'ts, plus tons of practical programming tips. I think this guy really knows what he's doing. (created libraries for that, too)

柏林苍穹下 2024-08-18 01:00:32

Nicolai Josuttis 在他的书中有一个用户定义迭代器的示例:C++ 标准库、教程和参考。

这是在线示例:

http://www.josuttis.com/libbook/iter/ assoiter.hpp
http://www.josuttis.com/libbook/iter/assoiter.cpp

Nicolai Josuttis has an example of a user defined iterator in his book: C++ Standard Library, a tutorial and a reference.

Here is the example online:

http://www.josuttis.com/libbook/iter/assoiter.hpp
http://www.josuttis.com/libbook/iter/assoiter.cpp

你怎么这么可爱啊 2024-08-18 01:00:32

看一下这篇文章,它描述了如何为您的类实现自定义虚拟迭代器:文章

它有一个显着的优点 - 您可以创建一个抽象基本迭代器类,并为您自己的容器(也许还有一些 STL 容器)继承它并使用一些自定义迭代器。因此,您将能够动态地使用迭代器 - 您的函数将使用指向抽象迭代器类的指针,而其他代码将能够选择应使用哪些容器。

Take a look on this article which describes how to implement a custom virtual iterator for your classes: article

It has one significant advantage - you can create an abstract base iterator class and inherit it with a few custom iterators for your own containers and maybe for some STL containers. So you will be able to use iterators dynamically - your functions will use a pointer to the abstract iterator class while other code will be able to choose what containers should be used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文