Is there any function in stl that joins two std::queue
obj开发者_如何学Cects?
The std::queue
adapter doesn't support iteration so you'd actually have to roll your own method to do this. But given that you need this functionality, you should probably consider a different container. If you need random access, the probably std::deque
. If you only need front/back access like a queue consider std::list
which can be splice
d together in constant time.
There does not seem to be any options provided in stl, but I can think of some other things you can write yourself:
Write your own code to read one queue into another, but this is O(n).
Use
std::copy
to manipulate the underlyingstd::deque
containers, again O(n).Create your own container which is implemented in terms of
std::queue
, but can maintain multiple queues to simulate a join in O(1).
精彩评论