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