Iterating through a std::queue
The standard library of C provides a number of container adapters, one of which is the queue. As the linked documentation states, this adapter uses a Deque for underlying storage, which, according to the same documentation page, provides "random-access iterators". However, these iterators are not made accessible by the std::queue class, and there is no standard way of working around that. This is because:
The point of the standard container adapters is to provide a minimal interface.
This means that std::queue should be used to enqueue and dequeue elements, and not for iterating over its contents. If you need to iterate over a queue, then you may want to use a deque directly. It will provide you with all the functionality of a queue, and will allow you to iterate over it as well.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3