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.
The above is the detailed content of How can I iterate through a `std::queue` in C ?. For more information, please follow other related articles on the PHP Chinese website!