std::queue iteration

2019-01-04 11:35发布

I need to iterate over std::queue. www.cplusplus.com says:

By default, if no container class is specified for a particular queue class, the standard container class template deque is used.

So can I somehow get to the queue's underlying deque and iterate over it?

8条回答
Ridiculous、
2楼-- · 2019-01-04 12:35

std::queue is a container adaptor, and you can specify the container used (it defaults to use a deque). If you need functionality beyond that in the adaptor then just use a deque or another container directly.

查看更多
Bombasti
3楼-- · 2019-01-04 12:37

In short: No.

There is a hack, use vector as underlaid container, so queue::front will return valid reference, convert it to pointer an iterate until <= queue::back

查看更多
登录 后发表回答