Search code examples
c++pointersstliteratordeque

Getting the index of an element in a deque given a pointer to that element?


Is there any way to get the index of an element from a pointer to the element? To be specific, what I need is the index (or iterator) to the element preceding or following the one I point. I know that when using vectors you can easily do the arithmetics but in a deque it is not so easy.

I have to use deque. Vectors are not an option.


Solution

  • I believe the answer is no. But why not use iterators rather than pointers throughout?