In my project I use the std::queue class. I would like to know what happen if I do the following.
- Get a a pointer of a element inside the queue (note: a pointer and not a iterator).
- I make modification in the queue like push and pop in the queue (pop element which is not the pointed by the previous pointer)
Does my pointer still point on the same element I specify in the beginning ? Is it defined by the queue specification?
std::queueuses a sequence container for its implementation. By default,std::dequeis used. With astd::deque, so long as all the insertions and erasures are at the beginning or the end of the container, references and pointers to elements in the container are not invalidated.However, I don’t know how you are going to get a pointer to an element in the queue; it doesn’t provide functionality for that (you can only get a reference to the first and last elements in the queue).