我正在使用std :: queue来实现JobQueue类.(基本上这个类以FIFO方式处理每个作业).在一种情况下,我想一次性清除队列(从队列中删除所有作业).我没有看到std :: queue类中有任何明确的方法.
如何有效地为JobQueue类实现clear方法?
我有一个简单的循环弹出解决方案,但我正在寻找更好的方法.
//Clears the job queue
void JobQueue ::clearJobs()
{
// I want to avoid pop in a loop
while (!m_Queue.empty())
{
m_Queue.pop();
}
}
Run Code Online (Sandbox Code Playgroud)