问题描述
我想使用循环列表。
没有实现我自己的()我的选项是什么?
具体来说,我想做的是迭代对象列表。当我的迭代器到达列表的末尾时,它应该自动返回到开始。 (是的,我知道这可能很危险。)
:circular_iterator永远不会与CircularList :: end()相等,因此您可以随时取消引用此迭代器。
$ b但是,这里有一个,这可能会有所帮助。 / p>
如果你不需要任何东西,你可以考虑使用向量
。你可以使用向量的大小 mod
来实现与循环列表大致相同的操作。
I want to use a circular list.
Short of implementing my own () 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.)
: "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 ++是否存在标准实现的循环列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!