保持数据的迭代器的向量 [英] Keeping vector of iterators of the data
问题描述
我有一个函数:
void get_good_items(const std :: vector< T>& data,std ::向量< XXX>& good_items);
此函数应检查所有数据并查找满足条件的项,并返回
什么是最好的,而不是 XXX
?
-
std :: vector< size_t>
包含所有好的索引。 -
-
std:
包含对项目的迭代器。std :: vector< T *>
:vector< std :: vector< T> :: iterator> - 其他?
编辑:
> good_items ?
许多东西...其中一个是从向量中删除它们并将它们保存在其他位置。
其中最重要的是我是如何访问数据
中的项目将快速取决于 good_items
?的结构?
编辑3:
我刚刚重申我的想法是错误的。不是最好保持原始指针(或聪明)作为向量的项目,所以我可以保持向量的真正的价值观(它们是指针),我不害怕重复,因为他们只是指针?
如果从原始向量中删除项目,您列出的每个方法都会有问题。
如果将项目添加到原始向量中,第二个和第三个将是有问题的。如果使用 push_back
添加项目,第一个不会有问题。
因此,我建议使用 std :: vector< size_t>
。
I have a function :
void get_good_items(const std::vector<T>& data,std::vector<XXX>& good_items);
This function should check all data and find items that satisfies a condition and return where they are in good_items.
what is best instead of XXX
?
std::vector<size_t>
that contains all good indices.std::vector<T*>
that contain a pointers to the items.std::vector<std::vector<T>::iterator>
that contains iterators to the items.- other ??
EDIT:
What will I do with the good_items
?
Many things... one of them is to delete them from the vector and save them in other place. maybe something else later
EDIT 2:
One of the most important for me is how will accessing the items in data
will be fast depending on the struct of good_items
?
EDIT 3:
I have just relized that my thought was wrong. Is not better to keep raw pointers(or smart) as items of the vector so I can keep the real values of the vector (which are pointers) and I do not afraid of heavy copy because they are just pointers?
If you remove items from the original vector, every one of the methods you listed will be a problem.
If you add items to the original vector, the second and third will be problematic. The first one won't be a problem if you use push_back
to add items.
All of them will be fine if you don't modify the original vector.
Given that, I would recommend using std::vector<size_t>
.
这篇关于保持数据的迭代器的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!