Why don't the standard C++ container adaptors provide a clear function?

后端 未结 6 1007
余生分开走
余生分开走 2020-12-10 01:48

Does anyone know why std::queue, std::stack, and std::priority_queue don\'t provide a clear() member function? I have to fake one like this:

st         


        
6条回答
  •  天命终不由人
    2020-12-10 02:21

    Deque has clear(). See, e.g., http://www.cplusplus.com/reference/stl/deque/clear.html.

    However, queue does not. But why would you choose queue over deque, anyway?

    The only reason to use the container adaptor queue instead of the container deque is to make it clear that you are performing only queue operations, and no other operations.

    (http://www.sgi.com/tech/stl/queue.html)

    So I guess clear() is not a queue operation, then.

提交回复
热议问题