I have requirement: for a function, I get the input as a stream of numbers. I mean, the function keeps on getting called with single number in each call. I am using std::queue
for storing the stream of numbers. I need to process a collected set of numbers only when some condition is satisfied. If the condition is not satisfied I need to put all the elements into the queue and then start storing new numbers in there. For emptying the queue, I couldn't find a clear()
method. So I am looping like this:
while(!q.empty())
q.pop();
I got an efficient algorithm for clearing a std::queue
at
How do I clear the std::queue efficiently?
My question is: Why doesn't std::queue
support a clear()
function?
Since std::deque
and std::vector
both support a clear()
method, what is the technical difficulty in supporting it for std::queue
?
Or is my above use case very rare and hence not supported?