Does a standard implementation of a Circular List exist for C++?(C++ 是否存在循环列表的标准实现?)
问题描述
我想使用循环列表.
如果没有实现我自己的(像这个人所做的),我有什么选择?>
特别是我想做的是迭代对象列表.当我的迭代器到达列表的末尾时,它应该自动返回到开头.(是的,我意识到这可能很危险.)
参见 Vladimir 对 circular_iterator
的定义:circular_iterator 将永远不会与 CircularList::end() 相等,因此您始终可以取消引用此迭代器."
没有标准的循环列表.
但是,有一个循环缓冲区 在 Boost 中,这可能会有所帮助.
如果您不需要任何花哨的东西,您可以考虑只使用 vector
并使用索引访问元素.你可以用向量的大小mod
你的索引来实现与循环列表大致相同的事情.
I want to use a circular list.
Short of implementing my own (like this person did) what are my options?
Specifically what I want to do is iterate over a list of objects. When my iterator reaches the end of the list, it should automatically return to the beginning. (Yes, I realize this could be dangerous.)
See Vladimir's definition of a circular_iterator
: "A circular_iterator will never be equal with CircularList::end(), thus you can always dereference this iterator."
There's no standard circular list.
However, there is a circular buffer in Boost, which might be helpful.
If you don't need anything fancy, you might consider just using a vector
and accessing the elements with an index. You can just mod
your index with the size of the vector to achieve much the same thing as a circular list.
这篇关于C++ 是否存在循环列表的标准实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 是否存在循环列表的标准实现?
基础教程推荐
- Windows Media Foundation 录制音频 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01