Reputation: 6768
In my project I use the std::queue class. I would like to know what happen if I do the following.
Does my pointer still point on the same element I specify in the beginning ? Is it defined by the queue specification?
Upvotes: 0
Views: 1283
Reputation: 355069
std::queue
uses a sequence container for its implementation. By default, std::deque
is used. With a std::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).
Upvotes: 1
Reputation: 73490
Just use a std::deque instead. std::queue is designed to prevent the user from doing anything non-queue like.
Upvotes: 1