Help with "iterating" through queue

How could I "iterate" through a queue without altering its contents? I want to basically copy one queue onto another but I don't want to use .pop() because it'll remove the items from the original stack.
There are no iterators in std::queue, but it can be just copied:

1
2
3
4
5
6
7
8
9
10
11
#include <queue>
int main()
{
        std::queue<int> q1;
        q1.push(1);
        q1.push(2);
        q1.push(3);

        std::queue<int> q2 = q1;
        q2 = q1;
}
If you want to iterate over the queue you can use std::deque instead. Just use push_back instead of push and pop_front instead of pop. You can iterate over a std::deque the same way you iterate over a std::vector.
If you feel like iterating through a queue it's likely the wrong container you're using.
Topic archived. No new replies allowed.