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

前端 未结 4 781
感情败类
感情败类 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:48

    According to http://www.cplusplus.com/reference/stl/queue/,

    queues are implemented as containers adaptors, which are classes that use an encapsulated object of a specific container class as its underlying container, providing a specific set of member functions to access it elements.

    which means that the queue uses an already existing container, and is just really is an interface to this container as a FIFO queue.

    This means queues are not meant to be cleared. If you need to clear a queue, this means you actually need to use an object that is not a queue, and therefore you should instead use the actual underlying container type, being a deque by default.

提交回复
热议问题