Why doesn't std::queue support a clear() function?

前端 未结 4 786
感情败类
感情败类 2021-02-01 16:12

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::q

4条回答
  •  孤街浪徒
    2021-02-01 16:52

    Added this to my growing list of 'make STL readable' functions:

    template  
    void Clear(std::queue& Queue) 
    {
        Queue = std::queue(); // Assign to empty queue
    }
    

    It's just a wrapper around sellibitze's excellent answer, but means I don't have to also add a comment every time I use the technique.

提交回复
热议问题