简体   繁体   中英

c++ vector of iterators

我知道我可以在一个vector<int*> onev_point_2_all等上使用for循环指向向量std::vector<int> vector<int*> onev_point_2_all 。但是我如何使用迭代器来实现这一点是否有一种创建迭代器向量的方法指针矢量?

You can have a vector of iterators, not necessary iterators of a vector and not necessarily iterators of the same collection, but they must all be of the same type.

You would not need the underlying collection to be able to dereference them, so if you know they are all valid iterators and that's all you want to do, you would have no problem doing that. If they are non-const iterators you can also set their values (if not set iterators).

If you need to check them to see if they are "end" iterators, or remove them from their collection then you will need to know the underlying collection behind the iterator. If they all come from the same collection that is straightforward, but if they come from different collections you would need to store a pointer to their underlying collection with them. Note that it would have to be a pointer to the underlying collection, not a reference, as if they are vector items they must be assignable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM