Possible to obtain a std::vector<T>::const_iterator from a multi index container index?

StackOverflow https://stackoverflow.com/questions/23139113

  •  05-07-2023
  •  | 
  •  

質問

I am converting some code in a system that serves the UI with an enumerator. Unfortunately the enumerator has been designed around the std::vector<T>::const_iterator. That is, it takes a begin and end iterator of type std::vector<T>::const_iterator.

I would like to convert the underlying container of the data source from a vector to a boost multi index container. This works well, until I have to serve the enumerator.

My question is, is it possible to convert a multi index container index iterator to a std::vector<T>::const_iterator?

役に立ちましたか?

解決

No, it's not possible; vectors are contiguous containers, but even random access indices do not provide data contiguity.

You'll need either to keep indices external to the vector, or recreate the vector as required.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top