开发者

c++ vector of iterators

开发者 https://www.devze.com 2023-01-22 00:59 出处:网络
I understand that I can point to number of vectors std::vector<int> using for loop on one vector<int*> onev_point_2_all etc.. but how do i do that using iterators is there a way of creatin

I understand that I can point to number of vectors std::vector<int> using for loop on one vector<int*> onev_point_2_all etc.. but how do i do that using iterators is there a way of creating a vector开发者_StackOverflow中文版 of iterators instead of a vector of pointers ?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消